﻿using Module_Debug.Hardware;
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Ports;
using System.Text;
using System.Threading;
using System.Windows.Forms;

namespace Module_Debug.VDDIC_Gamma
{
    public partial class CH13A11_Gamma : Form
    {
        CaSDK CaSDKObj = new CaSDK();
        CRC16 CRCData = new CRC16();
        Gamma_Addr GAMMAs = new Gamma_Addr();

        private ushort[] gamma_r = new ushort[33];
        private ushort[] gamma_g = new ushort[33];
        private ushort[] gamma_b = new ushort[33];

        private bool Listening = false;//是否没有执行完invoke相关操作   
        private bool IClosing = false;//是否正在关闭串口，执行Application.DoEvents，并阻止再次invoke 
        private List<byte> buffer = new List<byte>(2048);//默认分配1/16页内存，并始终限制不允许超过
        private double[,] D_lums;//目标值-单色
        private double[] D_lum;//目标值-白色

        private int index = 0;
        private int flag1 = 1; //lum
        private int flag2 = 1; //x
        private int flag3 = 1; //y
        private byte[] Send_buf = new byte[1];
        private byte[] Rec_tmp = new byte[1];

        //创建类型为Person的对象集合
        List<Setting.Gamma_Property> Diven_Gamma = new List<Setting.Gamma_Property>();
        List<Setting.Offset_Property> Diven_Offset = new List<Setting.Offset_Property>();
        string Path = System.AppDomain.CurrentDomain.BaseDirectory + "CH13A11" + ".txt";

        private static bool Gamma_adjust_timeout_flag = false;
        //Gamma绑点定义

        //监听挂载
        frmMain frmHelp = null;
        frmMain frmTop = null;

        public CH13A11_Gamma()
        {
            InitializeComponent();
        }

        private void CH13A11_Gamma_Load(object sender, EventArgs e)
        {
            Rbt_CH13A11_34points_CheckedChanged(sender, e);

        }
        public CH13A11_Gamma(frmMain CH13A11)
        {
            frmHelp = CH13A11;
            InitializeComponent();
            frmHelp.Child_window_hide_already = true;
            frmHelp.Child_Gamma_Window_Open_Enable = false;//防止重复开启子窗体            
        }
        //CH13A11 监听卸载
        private void CH13A11_Gamma_FormClosed(object sender, FormClosedEventArgs e)
        {
            ////frmHelp.comPort.Close()
            frmHelp.comPort.DataReceived -= new SerialDataReceivedEventHandler(CH13A11_DataReceived);
            frmHelp.comPort.DataReceived += new SerialDataReceivedEventHandler(frmHelp.SerialPort1_DataReceived);
            ////frmHelp.comPort.Open();
            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "CH13A11_Gamma_FormClosed！\r\n";
            frmHelp.Child_Gamma_Window_Open_Enable = true; //允许其他子窗体打开
            frmHelp.Child_window_hide_already = false;
            frmHelp.IC_comboBox.Enabled = true;
        }

        private void CH13A11_Gamma_VisibleChanged(object sender, EventArgs e)
        {
            if (frmHelp.Child_window_hide_already == false) //子窗体已开启标识
            {
                ////frmHelp.comPort.Close()
                frmHelp.comPort.DataReceived -= new SerialDataReceivedEventHandler(CH13A11_DataReceived);
                frmHelp.comPort.DataReceived += new SerialDataReceivedEventHandler(frmHelp.SerialPort1_DataReceived);
                ////frmHelp.comPort.Open();
                frmHelp.textBox1.Text = frmHelp.textBox1.Text + "CH13A11_Gamma_FormHide！\r\n";
                frmHelp.Child_window_hide_already = true; //子窗体已隐藏标识
            }
            else
            {
                frmHelp.comPort.DataReceived -= new SerialDataReceivedEventHandler(frmHelp.SerialPort1_DataReceived);
                frmHelp.comPort.DataReceived += new SerialDataReceivedEventHandler(CH13A11_DataReceived);
                frmHelp.textBox1.Text = frmHelp.textBox1.Text + "CH13A11_Gamma_FormOpened！\r\n";
                frmHelp.Child_window_hide_already = false; //子窗体已开启标识
            }
        }
        //串口接收
        private void CH13A11_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)//Getting data from Comm Port
        {
            if (IClosing) return;
            try
            {
                Listening = true;//设置标记，说明我已经开始处理数据，一会儿要使用系统UI的。         
                int n = frmHelp.comPort.BytesToRead;
                byte[] buf = new byte[n];
                byte data;

                frmHelp.comPort.Read(buf, 0, n);//读取缓冲数据     
                bool data_1_catched = false;//缓存记录数据是否捕获到    
                buffer.AddRange(buf);
                byte CRCH, CRCL;
                if (buffer.Count > 3)
                {
                    // 0x65: CH13A11的Gamma读写、寄存器读写、OTP读写    设置  返回
                    if (buffer[0] == 0x81 && Setting.TempRecord.cmdLen > 0)
                    {
                        if (buffer.Count >= Setting.TempRecord.cmdLen)
                        {
                            Rec_tmp = new byte[Setting.TempRecord.cmdLen];
                            byte[] crcTemp = new byte[Setting.TempRecord.cmdLen];
                            buffer.CopyTo(0, crcTemp, 0, Setting.TempRecord.cmdLen);

                            CRCData.CalculateCrc16(crcTemp, out CRCH, out CRCL);
                            if (buffer[Setting.TempRecord.cmdLen - 2] != CRCH && buffer[Setting.TempRecord.cmdLen - 1] != CRCL)     //CRC校验出错
                            {
                                buffer.RemoveRange(0, buffer.Count);
                            }
                            else
                            {
                                buffer.CopyTo(0, Rec_tmp, 0, Setting.TempRecord.cmdLen);//复制一条完整数据到具体的数据缓存   
                                data_1_catched = true;
                                buffer.RemoveRange(0, Setting.TempRecord.cmdLen);//正确分析一条数据，从缓存中移除数据。 
                            }
                        }
                    }
                    else if (((buffer[0] == 0x1D) || (buffer[0] == 0x0D) || (buffer[0] == 0x0A) || (buffer[0] == 0x2F) || (buffer[0] == 0x99) || (buffer[0] == 0x9e) || (buffer[0] == 0x9f)) && (Setting.TempRecord.cmdLen > 0))
                    {
                        if (buffer.Count >= Setting.TempRecord.cmdLen)
                        {
                            Rec_tmp = new byte[Setting.TempRecord.cmdLen];
                            byte[] crcTemp = new byte[Setting.TempRecord.cmdLen];
                            buffer.CopyTo(0, crcTemp, 0, Setting.TempRecord.cmdLen);

                            CRCData.CalculateCrc16(crcTemp, out CRCH, out CRCL);
                            if (buffer[Setting.TempRecord.cmdLen - 2] != CRCH && buffer[Setting.TempRecord.cmdLen - 1] != CRCL)     //CRC校验出错
                            {
                                buffer.RemoveRange(0, buffer.Count);
                            }
                            else
                            {
                                buffer.CopyTo(0, Rec_tmp, 0, Setting.TempRecord.cmdLen);//复制一条完整数据到具体的数据缓存   
                                data_1_catched = true;
                                buffer.RemoveRange(0, buffer.Count);  //正确分析一条数据，从缓存中移除数据。  
                            }
                        }
                    }

                    else
                    {
                        buffer.RemoveRange(0, buffer.Count);
                    }
                }
                if (data_1_catched)
                {
                    this.Invoke((EventHandler)(delegate
                    {
                        frmHelp.T1.Enabled = false; //停止超时计数
                        if (Rec_tmp[0] == 0x81)
                        {
                            switch (Rec_tmp[1])
                            {
                                case 0x07:
                                    {
                                        if (Rec_tmp[4] == 0x01)
                                        {
                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "GAMMA \totp OK！\r\n";
                                        }
                                        else if (Rec_tmp[4] == 0x00)
                                        {
                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "Other reg \totp OK！\r\n";
                                        }
                                        else if (Rec_tmp[4] == 0x02)
                                        {
                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "Demura \totp OK！\r\n";
                                        }
                                        else
                                        {
                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "\totp Error！\r\n";
                                        }

                                    }
                                    break;
                                case 0x08:
                                    {
                                        if (Rec_tmp[4] == 0x00)
                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "GAMMA \t写 OK！\r\n";
                                        else if (Rec_tmp[4] == 0x02)
                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "GAMMA \t写 ERROR！\r\n";
                                    }
                                    break;
                                case 0x09:
                                    {

                                        if (rbt_CH13A11_25points.Checked == true)
                                        {
                                            CH13A11_B0.Value = Decimal.Parse(((Rec_tmp[105] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[80].ToString());
                                            CH13A11_B1.Value = Decimal.Parse((Rec_tmp[105] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[81].ToString());
                                            CH13A11_B2.Value = Decimal.Parse(((Rec_tmp[106] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[82].ToString());
                                            CH13A11_B3.Value = Decimal.Parse((Rec_tmp[106] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[83].ToString());
                                            CH13A11_B4.Value = Decimal.Parse(((Rec_tmp[107] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[84].ToString());
                                            CH13A11_B5.Value = Decimal.Parse((Rec_tmp[107] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[85].ToString());
                                            CH13A11_B6.Value = Decimal.Parse(((Rec_tmp[108] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[86].ToString());
                                            CH13A11_B7.Value = Decimal.Parse((Rec_tmp[108] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[87].ToString());
                                            CH13A11_B8.Value = Decimal.Parse(((Rec_tmp[109] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[88].ToString());
                                            CH13A11_B9.Value = Decimal.Parse((Rec_tmp[109] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[89].ToString());
                                            CH13A11_B10.Value = Decimal.Parse(((Rec_tmp[110] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[90].ToString());
                                            CH13A11_B11.Value = Decimal.Parse((Rec_tmp[110] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[91].ToString());
                                            CH13A11_B12.Value = Decimal.Parse(((Rec_tmp[111] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[92].ToString());
                                            CH13A11_B13.Value = Decimal.Parse((Rec_tmp[111] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[93].ToString());
                                            CH13A11_B14.Value = Decimal.Parse(((Rec_tmp[112] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[94].ToString());
                                            CH13A11_B15.Value = Decimal.Parse((Rec_tmp[112] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[95].ToString());
                                            CH13A11_B16.Value = Decimal.Parse(((Rec_tmp[113] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[96].ToString());
                                            CH13A11_B17.Value = Decimal.Parse((Rec_tmp[113] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[97].ToString());
                                            CH13A11_B18.Value = Decimal.Parse(((Rec_tmp[114] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[98].ToString());
                                            CH13A11_B19.Value = Decimal.Parse((Rec_tmp[114] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[99].ToString());
                                            CH13A11_B20.Value = Decimal.Parse(((Rec_tmp[115] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[100].ToString());
                                            CH13A11_B21.Value = Decimal.Parse((Rec_tmp[115] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[101].ToString());
                                            CH13A11_B22.Value = Decimal.Parse(((Rec_tmp[116] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[102].ToString());
                                            CH13A11_B23.Value = Decimal.Parse((Rec_tmp[116] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[103].ToString());
                                            CH13A11_B24.Value = Decimal.Parse((Rec_tmp[117] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[104].ToString());

                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "蓝 Gamma数据\t读 OK！\r\n";

                                            CH13A11_G0.Value = Decimal.Parse(((Rec_tmp[67] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[42].ToString());
                                            CH13A11_G1.Value = Decimal.Parse((Rec_tmp[67] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[43].ToString());
                                            CH13A11_G2.Value = Decimal.Parse(((Rec_tmp[68] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[44].ToString());
                                            CH13A11_G3.Value = Decimal.Parse((Rec_tmp[68] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[45].ToString());
                                            CH13A11_G4.Value = Decimal.Parse(((Rec_tmp[69] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[46].ToString());
                                            CH13A11_G5.Value = Decimal.Parse((Rec_tmp[69] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[47].ToString());
                                            CH13A11_G6.Value = Decimal.Parse(((Rec_tmp[70] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[48].ToString());
                                            CH13A11_G7.Value = Decimal.Parse((Rec_tmp[70] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[49].ToString());
                                            CH13A11_G8.Value = Decimal.Parse(((Rec_tmp[71] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[50].ToString());
                                            CH13A11_G9.Value = Decimal.Parse((Rec_tmp[71] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[51].ToString());
                                            CH13A11_G10.Value = Decimal.Parse(((Rec_tmp[72] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[52].ToString());
                                            CH13A11_G11.Value = Decimal.Parse((Rec_tmp[72] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[53].ToString());
                                            CH13A11_G12.Value = Decimal.Parse(((Rec_tmp[73] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[54].ToString());
                                            CH13A11_G13.Value = Decimal.Parse((Rec_tmp[73] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[55].ToString());
                                            CH13A11_G14.Value = Decimal.Parse(((Rec_tmp[74] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[56].ToString());
                                            CH13A11_G15.Value = Decimal.Parse((Rec_tmp[74] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[57].ToString());
                                            CH13A11_G16.Value = Decimal.Parse(((Rec_tmp[75] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[58].ToString());
                                            CH13A11_G17.Value = Decimal.Parse((Rec_tmp[75] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[59].ToString());
                                            CH13A11_G18.Value = Decimal.Parse(((Rec_tmp[76] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[60].ToString());
                                            CH13A11_G19.Value = Decimal.Parse((Rec_tmp[76] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[61].ToString());
                                            CH13A11_G20.Value = Decimal.Parse(((Rec_tmp[77] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[62].ToString());
                                            CH13A11_G21.Value = Decimal.Parse((Rec_tmp[77] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[63].ToString());
                                            CH13A11_G22.Value = Decimal.Parse(((Rec_tmp[78] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[64].ToString());
                                            CH13A11_G23.Value = Decimal.Parse((Rec_tmp[78] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[65].ToString());
                                            CH13A11_G24.Value = Decimal.Parse((Rec_tmp[79] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[66].ToString());
                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "绿 Gamma数据\t读 OK！\r\n";

                                            CH13A11_R0.Value = Decimal.Parse(((Rec_tmp[29] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[4].ToString());
                                            CH13A11_R1.Value = Decimal.Parse((Rec_tmp[29] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[5].ToString());
                                            CH13A11_R2.Value = Decimal.Parse(((Rec_tmp[30] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[6].ToString());
                                            CH13A11_R3.Value = Decimal.Parse((Rec_tmp[30] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[7].ToString());
                                            CH13A11_R4.Value = Decimal.Parse(((Rec_tmp[31] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[8].ToString());
                                            CH13A11_R5.Value = Decimal.Parse((Rec_tmp[31] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[9].ToString());
                                            CH13A11_R6.Value = Decimal.Parse(((Rec_tmp[32] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[10].ToString());
                                            CH13A11_R7.Value = Decimal.Parse((Rec_tmp[32] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[11].ToString());
                                            CH13A11_R8.Value = Decimal.Parse(((Rec_tmp[33] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[12].ToString());
                                            CH13A11_R9.Value = Decimal.Parse((Rec_tmp[33] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[13].ToString());
                                            CH13A11_R10.Value = Decimal.Parse(((Rec_tmp[34] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[14].ToString());
                                            CH13A11_R11.Value = Decimal.Parse((Rec_tmp[34] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[15].ToString());
                                            CH13A11_R12.Value = Decimal.Parse(((Rec_tmp[35] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[16].ToString());
                                            CH13A11_R13.Value = Decimal.Parse((Rec_tmp[35] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[17].ToString());
                                            CH13A11_R14.Value = Decimal.Parse(((Rec_tmp[36] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[18].ToString());
                                            CH13A11_R15.Value = Decimal.Parse((Rec_tmp[36] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[19].ToString());
                                            CH13A11_R16.Value = Decimal.Parse(((Rec_tmp[37] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[20].ToString());
                                            CH13A11_R17.Value = Decimal.Parse((Rec_tmp[37] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[21].ToString());
                                            CH13A11_R18.Value = Decimal.Parse(((Rec_tmp[38] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[22].ToString());
                                            CH13A11_R19.Value = Decimal.Parse((Rec_tmp[38] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[23].ToString());
                                            CH13A11_R20.Value = Decimal.Parse(((Rec_tmp[39] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[24].ToString());
                                            CH13A11_R21.Value = Decimal.Parse((Rec_tmp[39] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[25].ToString());
                                            CH13A11_R22.Value = Decimal.Parse(((Rec_tmp[40] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[26].ToString());
                                            CH13A11_R23.Value = Decimal.Parse((Rec_tmp[40] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[27].ToString());
                                            CH13A11_R24.Value = Decimal.Parse((Rec_tmp[41] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[28].ToString());
                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "红 Gamma数据\t读 OK！\r\n";
                                        }
                                        else if (rbt_CH13A11_17points.Checked == true)
                                        {
                                            CH13A11_B0.Value = Decimal.Parse(((Rec_tmp[109] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[88].ToString());
                                            CH13A11_B1.Value = Decimal.Parse((Rec_tmp[109] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[89].ToString());
                                            CH13A11_B2.Value = Decimal.Parse(((Rec_tmp[110] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[90].ToString());
                                            CH13A11_B3.Value = Decimal.Parse((Rec_tmp[110] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[91].ToString());
                                            CH13A11_B4.Value = Decimal.Parse(((Rec_tmp[111] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[92].ToString());
                                            CH13A11_B5.Value = Decimal.Parse((Rec_tmp[111] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[93].ToString());
                                            CH13A11_B6.Value = Decimal.Parse(((Rec_tmp[112] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[94].ToString());
                                            CH13A11_B7.Value = Decimal.Parse((Rec_tmp[112] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[95].ToString());
                                            CH13A11_B8.Value = Decimal.Parse(((Rec_tmp[113] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[96].ToString());
                                            CH13A11_B9.Value = Decimal.Parse((Rec_tmp[113] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[97].ToString());
                                            CH13A11_B10.Value = Decimal.Parse(((Rec_tmp[114] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[98].ToString());
                                            CH13A11_B11.Value = Decimal.Parse((Rec_tmp[114] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[99].ToString());
                                            CH13A11_B12.Value = Decimal.Parse(((Rec_tmp[115] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[100].ToString());
                                            CH13A11_B13.Value = Decimal.Parse((Rec_tmp[115] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[101].ToString());
                                            CH13A11_B14.Value = Decimal.Parse(((Rec_tmp[116] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[102].ToString());
                                            CH13A11_B15.Value = Decimal.Parse((Rec_tmp[116] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[103].ToString());
                                            CH13A11_B16.Value = Decimal.Parse((Rec_tmp[117] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[104].ToString());

                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "蓝 Gamma数据\t读 OK！\r\n";

                                            CH13A11_G0.Value = Decimal.Parse(((Rec_tmp[71] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[50].ToString());
                                            CH13A11_G1.Value = Decimal.Parse((Rec_tmp[71] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[51].ToString());
                                            CH13A11_G2.Value = Decimal.Parse(((Rec_tmp[72] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[52].ToString());
                                            CH13A11_G3.Value = Decimal.Parse((Rec_tmp[72] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[53].ToString());
                                            CH13A11_G4.Value = Decimal.Parse(((Rec_tmp[73] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[54].ToString());
                                            CH13A11_G5.Value = Decimal.Parse((Rec_tmp[73] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[55].ToString());
                                            CH13A11_G6.Value = Decimal.Parse(((Rec_tmp[74] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[56].ToString());
                                            CH13A11_G7.Value = Decimal.Parse((Rec_tmp[74] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[57].ToString());
                                            CH13A11_G8.Value = Decimal.Parse(((Rec_tmp[75] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[58].ToString());
                                            CH13A11_G9.Value = Decimal.Parse((Rec_tmp[75] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[59].ToString());
                                            CH13A11_G10.Value = Decimal.Parse(((Rec_tmp[76] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[60].ToString());
                                            CH13A11_G11.Value = Decimal.Parse((Rec_tmp[76] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[61].ToString());
                                            CH13A11_G12.Value = Decimal.Parse(((Rec_tmp[77] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[62].ToString());
                                            CH13A11_G13.Value = Decimal.Parse((Rec_tmp[77] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[63].ToString());
                                            CH13A11_G14.Value = Decimal.Parse(((Rec_tmp[78] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[64].ToString());
                                            CH13A11_G15.Value = Decimal.Parse((Rec_tmp[78] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[65].ToString());
                                            CH13A11_G16.Value = Decimal.Parse((Rec_tmp[79] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[66].ToString());
                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "绿 Gamma数据\t读 OK！\r\n";

                                            CH13A11_R0.Value = Decimal.Parse(((Rec_tmp[33] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[12].ToString());
                                            CH13A11_R1.Value = Decimal.Parse((Rec_tmp[33] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[13].ToString());
                                            CH13A11_R2.Value = Decimal.Parse(((Rec_tmp[34] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[14].ToString());
                                            CH13A11_R3.Value = Decimal.Parse((Rec_tmp[34] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[15].ToString());
                                            CH13A11_R4.Value = Decimal.Parse(((Rec_tmp[35] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[16].ToString());
                                            CH13A11_R5.Value = Decimal.Parse((Rec_tmp[35] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[17].ToString());
                                            CH13A11_R6.Value = Decimal.Parse(((Rec_tmp[36] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[18].ToString());
                                            CH13A11_R7.Value = Decimal.Parse((Rec_tmp[36] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[19].ToString());
                                            CH13A11_R8.Value = Decimal.Parse(((Rec_tmp[37] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[20].ToString());
                                            CH13A11_R9.Value = Decimal.Parse((Rec_tmp[37] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[21].ToString());
                                            CH13A11_R10.Value = Decimal.Parse(((Rec_tmp[38] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[22].ToString());
                                            CH13A11_R11.Value = Decimal.Parse((Rec_tmp[38] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[23].ToString());
                                            CH13A11_R12.Value = Decimal.Parse(((Rec_tmp[39] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[24].ToString());
                                            CH13A11_R13.Value = Decimal.Parse((Rec_tmp[39] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[25].ToString());
                                            CH13A11_R14.Value = Decimal.Parse(((Rec_tmp[40] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[26].ToString());
                                            CH13A11_R15.Value = Decimal.Parse((Rec_tmp[40] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[27].ToString());
                                            CH13A11_R16.Value = Decimal.Parse((Rec_tmp[41] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[28].ToString());
                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "红 Gamma数据\t读 OK！\r\n";
                                        }
                                        else if (rbt_CH13A11_15points.Checked == true)
                                        {
                                            CH13A11_B0.Value = Decimal.Parse(((Rec_tmp[110] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[90].ToString());
                                            CH13A11_B1.Value = Decimal.Parse((Rec_tmp[110] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[91].ToString());
                                            CH13A11_B2.Value = Decimal.Parse(((Rec_tmp[111] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[92].ToString());
                                            CH13A11_B3.Value = Decimal.Parse((Rec_tmp[111] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[93].ToString());
                                            CH13A11_B4.Value = Decimal.Parse(((Rec_tmp[112] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[94].ToString());
                                            CH13A11_B5.Value = Decimal.Parse((Rec_tmp[112] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[95].ToString());
                                            CH13A11_B6.Value = Decimal.Parse(((Rec_tmp[113] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[96].ToString());
                                            CH13A11_B7.Value = Decimal.Parse((Rec_tmp[113] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[97].ToString());
                                            CH13A11_B8.Value = Decimal.Parse(((Rec_tmp[114] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[98].ToString());
                                            CH13A11_B9.Value = Decimal.Parse((Rec_tmp[114] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[99].ToString());
                                            CH13A11_B10.Value = Decimal.Parse(((Rec_tmp[115] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[100].ToString());
                                            CH13A11_B11.Value = Decimal.Parse((Rec_tmp[115] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[101].ToString());
                                            CH13A11_B12.Value = Decimal.Parse(((Rec_tmp[116] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[102].ToString());
                                            CH13A11_B13.Value = Decimal.Parse((Rec_tmp[116] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[103].ToString());
                                            CH13A11_B14.Value = Decimal.Parse((Rec_tmp[117] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[104].ToString());
                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "蓝 Gamma数据\t读 OK！\r\n";

                                            CH13A11_G0.Value = Decimal.Parse(((Rec_tmp[72] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[52].ToString());
                                            CH13A11_G1.Value = Decimal.Parse((Rec_tmp[72] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[53].ToString());
                                            CH13A11_G2.Value = Decimal.Parse(((Rec_tmp[73] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[54].ToString());
                                            CH13A11_G3.Value = Decimal.Parse((Rec_tmp[73] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[55].ToString());
                                            CH13A11_G4.Value = Decimal.Parse(((Rec_tmp[74] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[56].ToString());
                                            CH13A11_G5.Value = Decimal.Parse((Rec_tmp[74] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[57].ToString());
                                            CH13A11_G6.Value = Decimal.Parse(((Rec_tmp[75] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[58].ToString());
                                            CH13A11_G7.Value = Decimal.Parse((Rec_tmp[75] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[59].ToString());
                                            CH13A11_G8.Value = Decimal.Parse(((Rec_tmp[76] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[60].ToString());
                                            CH13A11_G9.Value = Decimal.Parse((Rec_tmp[76] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[61].ToString());
                                            CH13A11_G10.Value = Decimal.Parse(((Rec_tmp[77] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[62].ToString());
                                            CH13A11_G11.Value = Decimal.Parse((Rec_tmp[77] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[63].ToString());
                                            CH13A11_G12.Value = Decimal.Parse(((Rec_tmp[78] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[64].ToString());
                                            CH13A11_G13.Value = Decimal.Parse((Rec_tmp[78] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[65].ToString());
                                            CH13A11_G14.Value = Decimal.Parse((Rec_tmp[79] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[66].ToString());
                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "绿 Gamma数据\t读 OK！\r\n";

                                            CH13A11_R0.Value = Decimal.Parse(((Rec_tmp[34] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[14].ToString());
                                            CH13A11_R1.Value = Decimal.Parse((Rec_tmp[34] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[15].ToString());
                                            CH13A11_R2.Value = Decimal.Parse(((Rec_tmp[35] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[16].ToString());
                                            CH13A11_R3.Value = Decimal.Parse((Rec_tmp[35] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[17].ToString());
                                            CH13A11_R4.Value = Decimal.Parse(((Rec_tmp[36] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[18].ToString());
                                            CH13A11_R5.Value = Decimal.Parse((Rec_tmp[36] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[19].ToString());
                                            CH13A11_R6.Value = Decimal.Parse(((Rec_tmp[37] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[20].ToString());
                                            CH13A11_R7.Value = Decimal.Parse((Rec_tmp[37] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[21].ToString());
                                            CH13A11_R8.Value = Decimal.Parse(((Rec_tmp[38] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[22].ToString());
                                            CH13A11_R9.Value = Decimal.Parse((Rec_tmp[38] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[23].ToString());
                                            CH13A11_R10.Value = Decimal.Parse(((Rec_tmp[39] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[24].ToString());
                                            CH13A11_R11.Value = Decimal.Parse((Rec_tmp[39] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[25].ToString());
                                            CH13A11_R12.Value = Decimal.Parse(((Rec_tmp[40] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[26].ToString());
                                            CH13A11_R13.Value = Decimal.Parse((Rec_tmp[40] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[27].ToString());
                                            CH13A11_R14.Value = Decimal.Parse((Rec_tmp[41] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[28].ToString());

                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "红 Gamma数据\t读 OK！\r\n";
                                        }
                                        else if (rbt_CH13A11_34points.Checked == true)
                                        {
                                            if (Rec_tmp[3] == 0x01)
                                            {
                                                CH13A11_R0.Value = Decimal.Parse((Rec_tmp[4] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[5].ToString());
                                                CH13A11_R1.Value = Decimal.Parse(((Rec_tmp[4] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[6].ToString());

                                                CH13A11_R2.Value = Decimal.Parse((Rec_tmp[7] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[8].ToString());
                                                CH13A11_R3.Value = Decimal.Parse(((Rec_tmp[7] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[9].ToString());

                                                CH13A11_R4.Value = Decimal.Parse((Rec_tmp[10] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[11].ToString());
                                                CH13A11_R5.Value = Decimal.Parse(((Rec_tmp[10] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[12].ToString());

                                                CH13A11_R6.Value = Decimal.Parse((Rec_tmp[13] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[14].ToString());
                                                CH13A11_R7.Value = Decimal.Parse(((Rec_tmp[13] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[15].ToString());

                                                CH13A11_R8.Value = Decimal.Parse((Rec_tmp[16] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[17].ToString());
                                                CH13A11_R9.Value = Decimal.Parse(((Rec_tmp[16] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[18].ToString());

                                                CH13A11_R10.Value = Decimal.Parse((Rec_tmp[19] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[20].ToString());
                                                CH13A11_R11.Value = Decimal.Parse(((Rec_tmp[19] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[21].ToString());
                                                frmHelp.textBox1.Text = frmHelp.textBox1.Text + "红 Gamma1数据\t读 OK！\r\n";

                                                CH13A11_R12.Value = Decimal.Parse((Rec_tmp[22] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[23].ToString());
                                                CH13A11_R13.Value = Decimal.Parse(((Rec_tmp[22] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[24].ToString());

                                                CH13A11_R14.Value = Decimal.Parse((Rec_tmp[25] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[26].ToString());
                                                CH13A11_R15.Value = Decimal.Parse(((Rec_tmp[25] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[27].ToString());

                                                CH13A11_R16.Value = Decimal.Parse((Rec_tmp[28] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[29].ToString());
                                                CH13A11_R17.Value = Decimal.Parse(((Rec_tmp[28] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[30].ToString());

                                                CH13A11_R18.Value = Decimal.Parse((Rec_tmp[31] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[32].ToString());
                                                CH13A11_R19.Value = Decimal.Parse(((Rec_tmp[31] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[33].ToString());

                                                CH13A11_R20.Value = Decimal.Parse((Rec_tmp[34] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[35].ToString());
                                                CH13A11_R21.Value = Decimal.Parse(((Rec_tmp[34] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[36].ToString());

                                                CH13A11_R22.Value = Decimal.Parse((Rec_tmp[37] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[38].ToString());
                                                CH13A11_R23.Value = Decimal.Parse(((Rec_tmp[37] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[39].ToString());
                                                frmHelp.textBox1.Text = frmHelp.textBox1.Text + "红 Gamma2数据\t读 OK！\r\n";

                                                CH13A11_R24.Value = Decimal.Parse((Rec_tmp[40] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[41].ToString());
                                                CH13A11_R25.Value = Decimal.Parse(((Rec_tmp[40] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[42].ToString());

                                                CH13A11_R26.Value = Decimal.Parse((Rec_tmp[43] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[44].ToString());
                                                CH13A11_R27.Value = Decimal.Parse(((Rec_tmp[43] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[45].ToString());

                                                CH13A11_R28.Value = Decimal.Parse((Rec_tmp[46] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[47].ToString());
                                                CH13A11_R29.Value = Decimal.Parse(((Rec_tmp[46] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[48].ToString());

                                                CH13A11_R30.Value = Decimal.Parse((Rec_tmp[49] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[50].ToString());
                                                CH13A11_R31.Value = Decimal.Parse(((Rec_tmp[49] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[51].ToString());

                                                CH13A11_R32.Value = Decimal.Parse((Rec_tmp[52] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[53].ToString());
                                                CH13A11_R33.Value = Decimal.Parse(((Rec_tmp[52] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[54].ToString());
                                                frmHelp.textBox1.Text = frmHelp.textBox1.Text + "红 Gamma3数据\t读 OK！\r\n";
                                            }
                                            else if (Rec_tmp[3] == 0x02)
                                            {
                                                CH13A11_G0.Value = Decimal.Parse((Rec_tmp[4] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[5].ToString());
                                                CH13A11_G1.Value = Decimal.Parse(((Rec_tmp[4] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[6].ToString());

                                                CH13A11_G2.Value = Decimal.Parse((Rec_tmp[7] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[8].ToString());
                                                CH13A11_G3.Value = Decimal.Parse(((Rec_tmp[7] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[9].ToString());

                                                CH13A11_G4.Value = Decimal.Parse((Rec_tmp[10] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[11].ToString());
                                                CH13A11_G5.Value = Decimal.Parse(((Rec_tmp[10] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[12].ToString());

                                                CH13A11_G6.Value = Decimal.Parse((Rec_tmp[13] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[14].ToString());
                                                CH13A11_G7.Value = Decimal.Parse(((Rec_tmp[13] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[15].ToString());

                                                CH13A11_G8.Value = Decimal.Parse((Rec_tmp[16] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[17].ToString());
                                                CH13A11_G9.Value = Decimal.Parse(((Rec_tmp[16] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[18].ToString());

                                                CH13A11_G10.Value = Decimal.Parse((Rec_tmp[19] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[20].ToString());
                                                CH13A11_G11.Value = Decimal.Parse(((Rec_tmp[19] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[21].ToString());
                                                frmHelp.textBox1.Text = frmHelp.textBox1.Text + "绿 Gamma1数据\t读 OK！\r\n";

                                                CH13A11_G12.Value = Decimal.Parse((Rec_tmp[22] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[23].ToString());
                                                CH13A11_G13.Value = Decimal.Parse(((Rec_tmp[22] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[24].ToString());

                                                CH13A11_G14.Value = Decimal.Parse((Rec_tmp[25] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[26].ToString());
                                                CH13A11_G15.Value = Decimal.Parse(((Rec_tmp[25] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[27].ToString());

                                                CH13A11_G16.Value = Decimal.Parse((Rec_tmp[28] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[29].ToString());
                                                CH13A11_G17.Value = Decimal.Parse(((Rec_tmp[28] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[30].ToString());

                                                CH13A11_G18.Value = Decimal.Parse((Rec_tmp[31] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[32].ToString());
                                                CH13A11_G19.Value = Decimal.Parse(((Rec_tmp[31] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[33].ToString());

                                                CH13A11_G20.Value = Decimal.Parse((Rec_tmp[34] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[35].ToString());
                                                CH13A11_G21.Value = Decimal.Parse(((Rec_tmp[34] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[36].ToString());

                                                CH13A11_G22.Value = Decimal.Parse((Rec_tmp[37] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[38].ToString());
                                                CH13A11_G23.Value = Decimal.Parse(((Rec_tmp[37] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[39].ToString());
                                                frmHelp.textBox1.Text = frmHelp.textBox1.Text + "绿 Gamma2数据\t读 OK！\r\n";

                                                CH13A11_G24.Value = Decimal.Parse((Rec_tmp[40] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[41].ToString());
                                                CH13A11_G25.Value = Decimal.Parse(((Rec_tmp[40] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[42].ToString());

                                                CH13A11_G26.Value = Decimal.Parse((Rec_tmp[43] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[44].ToString());
                                                CH13A11_G27.Value = Decimal.Parse(((Rec_tmp[43] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[45].ToString());

                                                CH13A11_G28.Value = Decimal.Parse((Rec_tmp[46] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[47].ToString());
                                                CH13A11_G29.Value = Decimal.Parse(((Rec_tmp[46] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[48].ToString());

                                                CH13A11_G30.Value = Decimal.Parse((Rec_tmp[49] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[50].ToString());
                                                CH13A11_G31.Value = Decimal.Parse(((Rec_tmp[49] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[51].ToString());

                                                CH13A11_G32.Value = Decimal.Parse((Rec_tmp[52] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[53].ToString());
                                                CH13A11_G33.Value = Decimal.Parse(((Rec_tmp[52] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[54].ToString());
                                                frmHelp.textBox1.Text = frmHelp.textBox1.Text + "绿 Gamma3数据\t读 OK！\r\n";

                                            }
                                            else if (Rec_tmp[3] == 0x03)
                                            {
                                                CH13A11_B0.Value = Decimal.Parse((Rec_tmp[4] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[5].ToString());
                                                CH13A11_B1.Value = Decimal.Parse(((Rec_tmp[4] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[6].ToString());

                                                CH13A11_B2.Value = Decimal.Parse((Rec_tmp[7] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[8].ToString());
                                                CH13A11_B3.Value = Decimal.Parse(((Rec_tmp[7] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[9].ToString());

                                                CH13A11_B4.Value = Decimal.Parse((Rec_tmp[10] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[11].ToString());
                                                CH13A11_B5.Value = Decimal.Parse(((Rec_tmp[10] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[12].ToString());

                                                CH13A11_B6.Value = Decimal.Parse((Rec_tmp[13] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[14].ToString());
                                                CH13A11_B7.Value = Decimal.Parse(((Rec_tmp[13] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[15].ToString());

                                                CH13A11_B8.Value = Decimal.Parse((Rec_tmp[16] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[17].ToString());
                                                CH13A11_B9.Value = Decimal.Parse(((Rec_tmp[16] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[18].ToString());

                                                CH13A11_B10.Value = Decimal.Parse((Rec_tmp[19] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[20].ToString());
                                                CH13A11_B11.Value = Decimal.Parse(((Rec_tmp[19] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[21].ToString());
                                                frmHelp.textBox1.Text = frmHelp.textBox1.Text + "蓝 Gamma1数据\t读 OK！\r\n";

                                                CH13A11_B12.Value = Decimal.Parse((Rec_tmp[22] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[23].ToString());
                                                CH13A11_B13.Value = Decimal.Parse(((Rec_tmp[22] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[24].ToString());

                                                CH13A11_B14.Value = Decimal.Parse((Rec_tmp[25] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[26].ToString());
                                                CH13A11_B15.Value = Decimal.Parse(((Rec_tmp[25] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[27].ToString());

                                                CH13A11_B16.Value = Decimal.Parse((Rec_tmp[28] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[29].ToString());
                                                CH13A11_B17.Value = Decimal.Parse(((Rec_tmp[28] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[30].ToString());

                                                CH13A11_B18.Value = Decimal.Parse((Rec_tmp[31] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[32].ToString());
                                                CH13A11_B19.Value = Decimal.Parse(((Rec_tmp[31] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[33].ToString());

                                                CH13A11_B20.Value = Decimal.Parse((Rec_tmp[34] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[35].ToString());
                                                CH13A11_B21.Value = Decimal.Parse(((Rec_tmp[34] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[36].ToString());

                                                CH13A11_B22.Value = Decimal.Parse((Rec_tmp[37] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[38].ToString());
                                                CH13A11_B23.Value = Decimal.Parse(((Rec_tmp[37] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[39].ToString());
                                                frmHelp.textBox1.Text = frmHelp.textBox1.Text + "蓝 Gamma2数据\t读 OK！\r\n";

                                                CH13A11_B24.Value = Decimal.Parse((Rec_tmp[40] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[41].ToString());
                                                CH13A11_B25.Value = Decimal.Parse(((Rec_tmp[40] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[42].ToString());

                                                CH13A11_B26.Value = Decimal.Parse((Rec_tmp[43] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[44].ToString());
                                                CH13A11_B27.Value = Decimal.Parse(((Rec_tmp[43] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[45].ToString());

                                                CH13A11_B28.Value = Decimal.Parse((Rec_tmp[46] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[47].ToString());
                                                CH13A11_B29.Value = Decimal.Parse(((Rec_tmp[46] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[48].ToString());

                                                CH13A11_B30.Value = Decimal.Parse((Rec_tmp[49] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[50].ToString());
                                                CH13A11_B31.Value = Decimal.Parse(((Rec_tmp[49] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[51].ToString());

                                                CH13A11_B32.Value = Decimal.Parse((Rec_tmp[52] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[53].ToString());
                                                CH13A11_B33.Value = Decimal.Parse(((Rec_tmp[52] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[54].ToString());
                                                frmHelp.textBox1.Text = frmHelp.textBox1.Text + "蓝 Gamma3数据\t读 OK！\r\n";

                                            }
                                        }
                                        else if (rbt_CH13A11_19points.Checked == true)
                                        {
                                            CH13A11_B0.Value = Decimal.Parse(((Rec_tmp[108] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[86].ToString());
                                            CH13A11_B1.Value = Decimal.Parse((Rec_tmp[108] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[87].ToString());
                                            CH13A11_B2.Value = Decimal.Parse(((Rec_tmp[109] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[88].ToString());
                                            CH13A11_B3.Value = Decimal.Parse((Rec_tmp[109] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[89].ToString());
                                            CH13A11_B4.Value = Decimal.Parse(((Rec_tmp[110] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[90].ToString());
                                            CH13A11_B5.Value = Decimal.Parse((Rec_tmp[110] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[91].ToString());
                                            CH13A11_B6.Value = Decimal.Parse(((Rec_tmp[111] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[92].ToString());
                                            CH13A11_B7.Value = Decimal.Parse((Rec_tmp[111] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[93].ToString());
                                            CH13A11_B8.Value = Decimal.Parse(((Rec_tmp[112] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[94].ToString());
                                            CH13A11_B9.Value = Decimal.Parse((Rec_tmp[112] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[95].ToString());
                                            CH13A11_B10.Value = Decimal.Parse(((Rec_tmp[113] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[96].ToString());
                                            CH13A11_B11.Value = Decimal.Parse((Rec_tmp[113] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[97].ToString());
                                            CH13A11_B12.Value = Decimal.Parse(((Rec_tmp[114] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[98].ToString());
                                            CH13A11_B13.Value = Decimal.Parse((Rec_tmp[114] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[99].ToString());
                                            CH13A11_B14.Value = Decimal.Parse(((Rec_tmp[115] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[100].ToString());
                                            CH13A11_B15.Value = Decimal.Parse((Rec_tmp[115] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[101].ToString());
                                            CH13A11_B16.Value = Decimal.Parse(((Rec_tmp[116] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[102].ToString());
                                            CH13A11_B17.Value = Decimal.Parse((Rec_tmp[116] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[103].ToString());
                                            CH13A11_B18.Value = Decimal.Parse((Rec_tmp[117] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[104].ToString());

                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "蓝 Gamma数据\t读 OK！\r\n";

                                            CH13A11_G0.Value = Decimal.Parse(((Rec_tmp[70] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[48].ToString());
                                            CH13A11_G1.Value = Decimal.Parse((Rec_tmp[70] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[49].ToString());
                                            CH13A11_G2.Value = Decimal.Parse(((Rec_tmp[71] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[50].ToString());
                                            CH13A11_G3.Value = Decimal.Parse((Rec_tmp[71] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[51].ToString());
                                            CH13A11_G4.Value = Decimal.Parse(((Rec_tmp[72] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[52].ToString());
                                            CH13A11_G5.Value = Decimal.Parse((Rec_tmp[72] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[53].ToString());
                                            CH13A11_G6.Value = Decimal.Parse(((Rec_tmp[73] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[54].ToString());
                                            CH13A11_G7.Value = Decimal.Parse((Rec_tmp[73] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[55].ToString());
                                            CH13A11_G8.Value = Decimal.Parse(((Rec_tmp[74] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[56].ToString());
                                            CH13A11_G9.Value = Decimal.Parse((Rec_tmp[74] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[57].ToString());
                                            CH13A11_G10.Value = Decimal.Parse(((Rec_tmp[75] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[58].ToString());
                                            CH13A11_G11.Value = Decimal.Parse((Rec_tmp[75] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[59].ToString());
                                            CH13A11_G12.Value = Decimal.Parse(((Rec_tmp[76] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[60].ToString());
                                            CH13A11_G13.Value = Decimal.Parse((Rec_tmp[76] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[61].ToString());
                                            CH13A11_G14.Value = Decimal.Parse(((Rec_tmp[77] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[62].ToString());
                                            CH13A11_G15.Value = Decimal.Parse((Rec_tmp[77] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[63].ToString());
                                            CH13A11_G16.Value = Decimal.Parse(((Rec_tmp[78] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[64].ToString());
                                            CH13A11_G17.Value = Decimal.Parse((Rec_tmp[78] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[65].ToString());
                                            CH13A11_G18.Value = Decimal.Parse((Rec_tmp[79] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[66].ToString());
                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "绿 Gamma数据\t读 OK！\r\n";

                                            CH13A11_R0.Value = Decimal.Parse(((Rec_tmp[32] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[10].ToString());
                                            CH13A11_R1.Value = Decimal.Parse((Rec_tmp[32] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[11].ToString());
                                            CH13A11_R2.Value = Decimal.Parse(((Rec_tmp[33] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[12].ToString());
                                            CH13A11_R3.Value = Decimal.Parse((Rec_tmp[33] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[13].ToString());
                                            CH13A11_R4.Value = Decimal.Parse(((Rec_tmp[34] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[14].ToString());
                                            CH13A11_R5.Value = Decimal.Parse((Rec_tmp[34] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[15].ToString());
                                            CH13A11_R6.Value = Decimal.Parse(((Rec_tmp[35] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[16].ToString());
                                            CH13A11_R7.Value = Decimal.Parse((Rec_tmp[35] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[17].ToString());
                                            CH13A11_R8.Value = Decimal.Parse(((Rec_tmp[36] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[18].ToString());
                                            CH13A11_R9.Value = Decimal.Parse((Rec_tmp[36] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[19].ToString());
                                            CH13A11_R10.Value = Decimal.Parse(((Rec_tmp[37] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[20].ToString());
                                            CH13A11_R11.Value = Decimal.Parse((Rec_tmp[37] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[21].ToString());
                                            CH13A11_R12.Value = Decimal.Parse(((Rec_tmp[38] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[22].ToString());
                                            CH13A11_R13.Value = Decimal.Parse((Rec_tmp[38] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[23].ToString());
                                            CH13A11_R14.Value = Decimal.Parse(((Rec_tmp[39] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[24].ToString());
                                            CH13A11_R15.Value = Decimal.Parse((Rec_tmp[39] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[25].ToString());
                                            CH13A11_R16.Value = Decimal.Parse(((Rec_tmp[40] >> 4) & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[26].ToString());
                                            CH13A11_R17.Value = Decimal.Parse((Rec_tmp[40] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[27].ToString());
                                            CH13A11_R18.Value = Decimal.Parse((Rec_tmp[41] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[28].ToString());
                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "红 Gamma数据\t读 OK！\r\n";
                                        }

                                    }
                                    break;
                                case 0x0D:
                                    {
                                        if (Rec_tmp[3] == 0x00)
                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "OTP \t写 OK！\r\n";
                                        else if (Rec_tmp[3] == 0x02)
                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "OTP \t写 ERROR！\r\n";
                                    }
                                    break;

                                default: break;
                            }
                        }
                        //--------------------------------------------Demura----------------------------------------
                        else if (Rec_tmp[0] == 0x2F)  //Demura
                        {
                            switch (Rec_tmp[1])
                            {
                                case 0x01:
                                    {
                                        txttip.Text += "Demura RAM Enable\r\n";
                                    }
                                    break;
                                case 0x0B:
                                    {
                                        txttip.Text += "Demura RAM Addr2 Enable\r\n";
                                    }
                                    break;
                                case 0x0D:
                                    {
                                        txttip.Text += "Demura RAM Addr3 Addr Enable\r\n";
                                    }
                                    break;
                                case 0x0F:
                                    {
                                        txttip.Text += "Demura RAM Addr4 Addr Enable\r\n";
                                    }
                                    break;
                                case 0x02:
                                    {
                                        txttip.Text += "Demura RAM Disable\r\n";
                                    }
                                    break;
                                case 0x03:
                                    {
                                        if (Rec_tmp[4] == 0xff)
                                        {
                                            txttip.Text += "Demura RAM write Flash fail ! \r\n";
                                            // MessageBox.Show("载入失败！");
                                        }
                                        else
                                        {
                                            txttip.Text += Rec_tmp[4].ToString("x2") + "Demura RAM Write Flash Complete ! \r\n";
                                            // MessageBox.Show("载入完成！");
                                        }
                                    }
                                    break;
                                case 0x0A:
                                    {
                                        txttip.Text += Rec_tmp[4].ToString("x2") + "Demura RAM Write Flash2 Complete ! \r\n";
                                        // MessageBox.Show("载入完成！");
                                    }
                                    break;
                                case 0x0C:
                                    {
                                        txttip.Text += Rec_tmp[4].ToString("x2") + "Demura RAM Write Flash3 Complete ! \r\n";
                                        // MessageBox.Show("载入完成！");
                                    }
                                    break;
                                case 0x0E:
                                    {
                                        txttip.Text += Rec_tmp[4].ToString("x2") + "Demura RAM Write Flash4 Complete ! \r\n";
                                        //  MessageBox.Show("载入完成！");
                                    }
                                    break;

                                case 0x04:
                                    {
                                        txttip.Text += "Checksum: " + Rec_tmp[4].ToString("x") + "," + Rec_tmp[5].ToString("x") + "," + Rec_tmp[6].ToString("x") + "," + Rec_tmp[7].ToString("x") + "\r\n";
                                    }
                                    break;
                                case 0x05:
                                    {
                                        txttip.Text += "Flash Erase Success ! \r\n";
                                    }
                                    break;
                                case 0x06:
                                    {
                                        txttip.Text += "flash ID: " + Rec_tmp[4].ToString("x") + "," + Rec_tmp[5].ToString("x") + "," + Rec_tmp[6].ToString("x") + "\r\n";
                                    }
                                    break;
                                case 0x07:
                                    {
                                        txttip.Text += "Demura function on \r\n";
                                    }
                                    break;
                                case 0x08:
                                    {
                                        txttip.Text += "Demura function off \r\n";
                                    }
                                    break;
                                case 0x09:
                                    {
                                        txttip.Text += "Demura OTP complete \r\n";
                                    }
                                    break;
                                default:
                                    break;
                            }
                        }
                        //--------------------------------------------通用读写----------------------------------------------
                        else if (Rec_tmp[0] == 0x99) //GENWR
                        {
                            switch (Rec_tmp[1])
                            {
                                case 0x01:
                                    {
                                        if (Rec_tmp[4] == 0x00)
                                            txttip.Text = txttip.Text + "DDIC 寄存器\t写 OK！\r\n";
                                    }
                                    break;
                                case 0x02:
                                    {
                                        string tmp = "";                    //8bit  read
                                        {
                                            for (int i = 3; i <= (Rec_tmp[2] + 2); i++)
                                            {
                                                if (i == (Rec_tmp[2] + 2))
                                                {
                                                    tmp = tmp + String.Format("{0:X2}", Rec_tmp[i]);//16进制
                                                }
                                                else
                                                {
                                                    tmp = tmp + String.Format("{0:X2}", Rec_tmp[i]) + ",";//16进制
                                                }
                                                // ReadBackarr[i] = Rec_tmp[i];
                                            }
                                        }
                                        txttip.Text += "DDIC 8bit寄存器--读 OK！\r\n";
                                        txttip.AppendText(tmp + "\r\n");

                                        Application.DoEvents();

                                    }
                                    break;
                                case 0x03:
                                    {
                                        string tmp = "";
                                        tmp = tmp + String.Format("{0:X2}", Rec_tmp[3]) + ",";  //16进制
                                        tmp = tmp + String.Format("{0:X2}", Rec_tmp[4]) + ",";//16进制
                                        tmp = tmp + String.Format("{0:X2}", Rec_tmp[5]);      //16进制

                                        txttip.Text += "DDIC 16bit寄存器--读 OK！\r\n";
                                        txttip.AppendText(tmp + "\r\n");

                                        Application.DoEvents();

                                    }
                                    break;
                                case 0x04:
                                    {
                                        if (Rec_tmp[3] == 0x00)
                                        {
                                            txttip.Text += "vpp off！\r\n";
                                        }
                                        else if (Rec_tmp[3] == 0x01)
                                        {
                                            txttip.Text += "vpp on！\r\n";
                                        }
                                    }
                                    break;
                            }
                        }
                        //----------------------------------------------------------------------------------------------------                       
                        else if (Rec_tmp[0] == 0x9f)    //小黄窗的通用命令读写
                        {
                            txttip.Text += "[" + DateTime.Now.ToLongTimeString().ToString() + "]：" + "命令已执行" + "\r\n";
                            txttip.SelectionStart = this.txttip.Text.Length;
                            txttip.ScrollToCaret();//滚动到光标处
                            if (txttip.Lines.Length > 50) txttip.Text = null;
                        }
                        frmHelp.textBox1.SelectionStart = this.frmHelp.textBox1.Text.Length;
                        frmHelp.textBox1.ScrollToCaret();//滚动到光标处
                        if (frmHelp.textBox1.Lines.Length > 50) frmHelp.textBox1.Text = null;
                    }));
                }
            }
            finally
            {
                Listening = false;
            }
        }

        //Gamma载入
        private void CH13A11_LoadGamma_Click(object sender, EventArgs e)
        {
            OpenFileDialog of = new OpenFileDialog();
            string strtmp = "";
            of.Filter = @"csv文件(*.csv)|*.csv|所有文件(*.*)|*.*"; ;
            of.Title = "打开Gamma文件";

            if (of.ShowDialog() == DialogResult.OK)
            {
                //读取文本信息
                FileStream fs = new FileStream(of.FileName, FileMode.Open, FileAccess.Read);
                StreamReader streamReader = new StreamReader(fs, Encoding.GetEncoding("GBK"));
                streamReader.BaseStream.Seek(0, SeekOrigin.Begin);
                string strLine = streamReader.ReadLine();
                //循环读取文本信息
                while (!string.IsNullOrEmpty(strLine))
                {
                    strtmp = strtmp + strLine + ",";
                    strLine = streamReader.ReadLine(); //循环读取下一行
                }
                fs.Close(); //关闭流
                streamReader.Close();
                string[] arrtmp = strtmp.Split(new Char[] { ',' });
                CH13A11_R0.Text = arrtmp[1].ToString(); CH13A11_G0.Text = arrtmp[3].ToString(); CH13A11_B0.Text = arrtmp[5].ToString();
                CH13A11_R1.Text = arrtmp[7].ToString(); CH13A11_G1.Text = arrtmp[9].ToString(); CH13A11_B1.Text = arrtmp[11].ToString();
                CH13A11_R2.Text = arrtmp[13].ToString(); CH13A11_G2.Text = arrtmp[15].ToString(); CH13A11_B2.Text = arrtmp[17].ToString();
                CH13A11_R3.Text = arrtmp[19].ToString(); CH13A11_G3.Text = arrtmp[21].ToString(); CH13A11_B3.Text = arrtmp[23].ToString();
                CH13A11_R4.Text = arrtmp[25].ToString(); CH13A11_G4.Text = arrtmp[27].ToString(); CH13A11_B4.Text = arrtmp[29].ToString();
                CH13A11_R5.Text = arrtmp[31].ToString(); CH13A11_G5.Text = arrtmp[33].ToString(); CH13A11_B5.Text = arrtmp[35].ToString();
                CH13A11_R6.Text = arrtmp[37].ToString(); CH13A11_G6.Text = arrtmp[39].ToString(); CH13A11_B6.Text = arrtmp[41].ToString();
                CH13A11_R7.Text = arrtmp[43].ToString(); CH13A11_G7.Text = arrtmp[45].ToString(); CH13A11_B7.Text = arrtmp[47].ToString();
                CH13A11_R8.Text = arrtmp[49].ToString(); CH13A11_G8.Text = arrtmp[51].ToString(); CH13A11_B8.Text = arrtmp[53].ToString();
                CH13A11_R9.Text = arrtmp[55].ToString(); CH13A11_G9.Text = arrtmp[57].ToString(); CH13A11_B9.Text = arrtmp[59].ToString();
                CH13A11_R10.Text = arrtmp[61].ToString(); CH13A11_G10.Text = arrtmp[63].ToString(); CH13A11_B10.Text = arrtmp[65].ToString();
                CH13A11_R11.Text = arrtmp[67].ToString(); CH13A11_G11.Text = arrtmp[69].ToString(); CH13A11_B11.Text = arrtmp[71].ToString();
                CH13A11_R12.Text = arrtmp[73].ToString(); CH13A11_G12.Text = arrtmp[75].ToString(); CH13A11_B12.Text = arrtmp[77].ToString();
                CH13A11_R13.Text = arrtmp[79].ToString(); CH13A11_G13.Text = arrtmp[81].ToString(); CH13A11_B13.Text = arrtmp[83].ToString();
                CH13A11_R14.Text = arrtmp[85].ToString(); CH13A11_G14.Text = arrtmp[87].ToString(); CH13A11_B14.Text = arrtmp[89].ToString();
                CH13A11_R15.Text = arrtmp[91].ToString(); CH13A11_G15.Text = arrtmp[93].ToString(); CH13A11_B15.Text = arrtmp[95].ToString();
                CH13A11_R16.Text = arrtmp[97].ToString(); CH13A11_G16.Text = arrtmp[99].ToString(); CH13A11_B16.Text = arrtmp[101].ToString();
                CH13A11_R17.Text = arrtmp[103].ToString(); CH13A11_G17.Text = arrtmp[105].ToString(); CH13A11_B17.Text = arrtmp[107].ToString();
                CH13A11_R18.Text = arrtmp[109].ToString(); CH13A11_G18.Text = arrtmp[111].ToString(); CH13A11_B18.Text = arrtmp[113].ToString();
                CH13A11_R19.Text = arrtmp[115].ToString(); CH13A11_G19.Text = arrtmp[117].ToString(); CH13A11_B19.Text = arrtmp[119].ToString();
                CH13A11_R20.Text = arrtmp[121].ToString(); CH13A11_G20.Text = arrtmp[123].ToString(); CH13A11_B20.Text = arrtmp[125].ToString();
                CH13A11_R21.Text = arrtmp[127].ToString(); CH13A11_G21.Text = arrtmp[129].ToString(); CH13A11_B21.Text = arrtmp[131].ToString();
                CH13A11_R22.Text = arrtmp[133].ToString(); CH13A11_G22.Text = arrtmp[135].ToString(); CH13A11_B22.Text = arrtmp[137].ToString();
                CH13A11_R23.Text = arrtmp[139].ToString(); CH13A11_G23.Text = arrtmp[141].ToString(); CH13A11_B23.Text = arrtmp[143].ToString();
                CH13A11_R24.Text = arrtmp[145].ToString(); CH13A11_G24.Text = arrtmp[147].ToString(); CH13A11_B24.Text = arrtmp[149].ToString();
                CH13A11_R25.Text = arrtmp[151].ToString(); CH13A11_G25.Text = arrtmp[153].ToString(); CH13A11_B25.Text = arrtmp[155].ToString();
                CH13A11_R26.Text = arrtmp[157].ToString(); CH13A11_G26.Text = arrtmp[159].ToString(); CH13A11_B26.Text = arrtmp[161].ToString();
                CH13A11_R27.Text = arrtmp[163].ToString(); CH13A11_G27.Text = arrtmp[165].ToString(); CH13A11_B27.Text = arrtmp[167].ToString();
                CH13A11_R28.Text = arrtmp[169].ToString(); CH13A11_G28.Text = arrtmp[171].ToString(); CH13A11_B28.Text = arrtmp[173].ToString();
                CH13A11_R29.Text = arrtmp[175].ToString(); CH13A11_G29.Text = arrtmp[177].ToString(); CH13A11_B29.Text = arrtmp[179].ToString();
                CH13A11_R30.Text = arrtmp[181].ToString(); CH13A11_G30.Text = arrtmp[183].ToString(); CH13A11_B30.Text = arrtmp[185].ToString();
                CH13A11_R31.Text = arrtmp[187].ToString(); CH13A11_G31.Text = arrtmp[189].ToString(); CH13A11_B31.Text = arrtmp[191].ToString();
                CH13A11_R32.Text = arrtmp[193].ToString(); CH13A11_G32.Text = arrtmp[195].ToString(); CH13A11_B32.Text = arrtmp[197].ToString();
                CH13A11_R33.Text = arrtmp[199].ToString(); CH13A11_G33.Text = arrtmp[201].ToString(); CH13A11_B33.Text = arrtmp[203].ToString();
            }
        }
        //Gamma保存
        private void CH13A11_SaveGamma_Click(object sender, EventArgs e)
        {
            SaveFileDialog sf = new SaveFileDialog(); //对话框
            sf.Filter = @"csv文件(*.csv)|*.csv|所有文件(*.*)|*.*"; //定义保存的文件的类型
            string str = "保存Gamma文件";
            if (sf.ShowDialog() == DialogResult.OK) //如果确定保存
            {
                if (sf.FileName == "") return; //如果没有输入文件名
                try
                {
                    StreamWriter sw = null; //文件流
                    sw = new StreamWriter(sf.FileName, false, Encoding.UTF8);
                    str = str + "R0," + CH13A11_R0.Text + "," + "G0," + CH13A11_G0.Text + "," + "B0," + CH13A11_B0.Text + "\r\n";
                    str = str + "R1," + CH13A11_R1.Text + "," + "G1," + CH13A11_G1.Text + "," + "B1," + CH13A11_B1.Text + "\r\n";
                    str = str + "R3," + CH13A11_R2.Text + "," + "G3," + CH13A11_G2.Text + "," + "B3," + CH13A11_B2.Text + "\r\n";
                    str = str + "R4," + CH13A11_R3.Text + "," + "G4," + CH13A11_G3.Text + "," + "B4," + CH13A11_B3.Text + "\r\n";
                    str = str + "R8," + CH13A11_R4.Text + "," + "G8," + CH13A11_G4.Text + "," + "B8," + CH13A11_B4.Text + "\r\n";
                    str = str + "R12," + CH13A11_R5.Text + "," + "G12," + CH13A11_G5.Text + "," + "B12," + CH13A11_B5.Text + "\r\n";
                    str = str + "R16," + CH13A11_R6.Text + "," + "G16," + CH13A11_G6.Text + "," + "B16," + CH13A11_B6.Text + "\r\n";
                    str = str + "R20," + CH13A11_R7.Text + "," + "G20," + CH13A11_G7.Text + "," + "B20," + CH13A11_B7.Text + "\r\n";
                    str = str + "R28," + CH13A11_R8.Text + "," + "G28," + CH13A11_G8.Text + "," + "B28," + CH13A11_B8.Text + "\r\n";
                    str = str + "R36," + CH13A11_R9.Text + "," + "G36," + CH13A11_G9.Text + "," + "B36," + CH13A11_B9.Text + "\r\n";
                    str = str + "R44," + CH13A11_R10.Text + "," + "G44," + CH13A11_G10.Text + "," + "B44," + CH13A11_B10.Text + "\r\n";
                    str = str + "R52," + CH13A11_R11.Text + "," + "G52," + CH13A11_G11.Text + "," + "B52," + CH13A11_B11.Text + "\r\n";
                    str = str + "R68," + CH13A11_R12.Text + "," + "G68," + CH13A11_G12.Text + "," + "B68," + CH13A11_B12.Text + "\r\n";
                    str = str + "R84," + CH13A11_R13.Text + "," + "G84," + CH13A11_G13.Text + "," + "B84," + CH13A11_B13.Text + "\r\n";
                    str = str + "R110," + CH13A11_R14.Text + "," + "G110," + CH13A11_G14.Text + "," + "B110," + CH13A11_B14.Text + "\r\n";
                    str = str + "R116," + CH13A11_R15.Text + "," + "G116," + CH13A11_G15.Text + "," + "B116," + CH13A11_B15.Text + "\r\n";
                    str = str + "R124," + CH13A11_R16.Text + "," + "G124," + CH13A11_G16.Text + "," + "B124," + CH13A11_B16.Text + "\r\n";
                    str = str + "R132," + CH13A11_R17.Text + "," + "G132," + CH13A11_G17.Text + "," + "B132," + CH13A11_B17.Text + "\r\n";
                    str = str + "R148," + CH13A11_R18.Text + "," + "G148," + CH13A11_G18.Text + "," + "B148," + CH13A11_B18.Text + "\r\n";
                    str = str + "R164," + CH13A11_R19.Text + "," + "G164," + CH13A11_G19.Text + "," + "B164," + CH13A11_B19.Text + "\r\n";
                    str = str + "R180," + CH13A11_R20.Text + "," + "G180," + CH13A11_G20.Text + "," + "B180," + CH13A11_B20.Text + "\r\n";
                    str = str + "R188," + CH13A11_R21.Text + "," + "G188," + CH13A11_G21.Text + "," + "B188," + CH13A11_B21.Text + "\r\n";
                    str = str + "R196," + CH13A11_R22.Text + "," + "G196," + CH13A11_G22.Text + "," + "B196," + CH13A11_B22.Text + "\r\n";
                    str = str + "R204," + CH13A11_R23.Text + "," + "G204," + CH13A11_G23.Text + "," + "B204," + CH13A11_B23.Text + "\r\n";
                    str = str + "R212," + CH13A11_R24.Text + "," + "G212," + CH13A11_G24.Text + "," + "B212," + CH13A11_B24.Text + "\r\n";
                    str = str + "R220," + CH13A11_R25.Text + "," + "G220," + CH13A11_G25.Text + "," + "B220," + CH13A11_B25.Text + "\r\n";
                    str = str + "R228," + CH13A11_R26.Text + "," + "G228," + CH13A11_G26.Text + "," + "B228," + CH13A11_B26.Text + "\r\n";
                    str = str + "R236," + CH13A11_R27.Text + "," + "G236," + CH13A11_G27.Text + "," + "B236," + CH13A11_B27.Text + "\r\n";
                    str = str + "R244," + CH13A11_R28.Text + "," + "G244," + CH13A11_G28.Text + "," + "B244," + CH13A11_B28.Text + "\r\n";
                    str = str + "R248," + CH13A11_R29.Text + "," + "G248," + CH13A11_G29.Text + "," + "B248," + CH13A11_B29.Text + "\r\n";
                    str = str + "R250," + CH13A11_R30.Text + "," + "G250," + CH13A11_G30.Text + "," + "B250," + CH13A11_B30.Text + "\r\n";
                    str = str + "R252," + CH13A11_R31.Text + "," + "G252," + CH13A11_G31.Text + "," + "B252," + CH13A11_B31.Text + "\r\n";
                    str = str + "R254," + CH13A11_R32.Text + "," + "G254," + CH13A11_G32.Text + "," + "B254," + CH13A11_B32.Text + "\r\n";
                    str = str + "R255," + CH13A11_R33.Text + "," + "G255," + CH13A11_G33.Text + "," + "B255," + CH13A11_B33.Text + "\r\n";

                    sw.WriteLine(str);
                    sw.Dispose(); //释放资源
                    sw.Close(); //关闭数据流
                    MessageBox.Show("Gamma保存OK！", "系统提示：");
                }
                catch
                {
                    MessageBox.Show("Gamma保存时发生错误，请再试！", "系统提示：");
                }
            }
        } //
        //Gamma载入

        //Gamma2.2目标值计算
        private void btnCalculateCH13A11_Click(object sender, EventArgs e)
        {
            double L_X, L_Y, L_Z;

            string[] arr = CH13A11_Gamma_SetBox.Lines;
            {
                try
                {
                    Diven_Gamma.Clear();
                    Diven_Offset.Clear();
                    for (int i = 0; i < arr.Length; i++)
                    {
                        string line = arr[i];
                        line = line.Replace(" ", "");
                        if (line.Contains("TUNING_SPEC"))
                        {
                            line = line.Replace("TUNING_SPEC", "");
                            line = line.Replace("(", "");
                            line = line.Replace(")", "");
                            string[] arr0 = line.Split(',');
                            Setting.Gamma_Property Gamma = new Setting.Gamma_Property(Convert.ToInt32(arr0[0]), Convert.ToDouble(arr0[1]), Convert.ToDouble(arr0[2]), Convert.ToDouble(arr0[3]), Convert.ToDouble(arr0[4]));
                            Diven_Gamma.Add(Gamma);
                        }
                        else if (line.Contains("LXY_SPEC"))
                        {
                            line = line.Replace("LXY_SPEC", "");
                            line = line.Replace("(", "");
                            line = line.Replace(")", "");
                            string[] arr1 = line.Split(',');
                            //将Offset对象放入集合
                            Setting.Offset_Property Offset = new Setting.Offset_Property(Convert.ToInt32(arr1[0]), Convert.ToDouble(arr1[1]), Convert.ToDouble(arr1[2]), Convert.ToDouble(arr1[3]));
                            Diven_Offset.Add(Offset);
                        }
                    }
                }
                catch
                {
                    MessageBox.Show("格式输入有误");
                }
            }
            //----------------------------------------------------------------------------
            try
            {
                txt_CH13A11_loff.Text = Diven_Offset[0].LUM_OFF.ToString();
                txt_CH13A11_xoff.Text = Diven_Offset[0].X_OFF.ToString();
                txt_CH13A11_yoff.Text = Diven_Offset[0].Y_OFF.ToString();

                int Total_points = Diven_Gamma[0].Points_num;
                D_lums = new double[Total_points, 3];
                D_lum = new double[Total_points];
                txt_CH13A11_gamma.Text = Diven_Gamma[0].Curve.ToString();
                txt_CH13A11_lum.Text = Diven_Gamma[0].Lum.ToString();
                txt_CH13A11_x.Text = Diven_Gamma[0].X.ToString();
                txt_CH13A11_y.Text = Diven_Gamma[0].Y.ToString();

                for (int i = 0; i < Total_points; i++)
                {   //Diven_Offset[p].NO 灰阶绑点                 
                    D_lum[i] = (Math.Pow((Diven_Offset[i].NO / 255.0), Diven_Gamma[0].Curve) * Diven_Gamma[0].Lum); //每绑点目标亮度
                    CaSDKObj.Lvxy_to_XYZ(D_lum[i], Diven_Gamma[0].X, Diven_Gamma[0].Y, out L_X, out L_Y, out L_Z);//X/Z/Z转换
                    D_lums[i, 0] = L_X; //R/B/G分亮度计算
                    D_lums[i, 1] = L_Y;
                    D_lums[i, 2] = L_Z;
                }
            }
            catch
            {
                MessageBox.Show("格式输入有误");
            }
        }
        //自动调节启动开关
        //bool gamma_227 = false;
        private void btnAutoGammas_CH13A11_Click(object sender, EventArgs e)
        {
            //gamma_227 = true;
            //flag1 = 1;
            //flag2 = 1;
            //flag3 = 1;
            btnCalculateCH13A11_Click(null, null);
            Thread.Sleep(10);
            frmHelp.numPatternR.Value = Diven_Offset[index].NO;
            frmHelp.numPatternG.Value = Diven_Offset[index].NO;
            frmHelp.numPatternB.Value = Diven_Offset[index].NO;
            Application.DoEvents();
            frmHelp.OLED_Show_Click(frmHelp.btnwhite, e);
            Thread.Sleep(10);
            T20.Enabled = true;
        }
        //自动调节关闭开关  
        private void CH13A11_Stop_Click(object sender, EventArgs e)
        {
            T20.Enabled = false;
            flag1 = 1;
            flag2 = 1;
            flag3 = 1;
        }

        private void T20_Tick(object sender, EventArgs e)
        {
            if (rbt_CH13A11_17points.Checked == true)
            {
                CH13A11_17P_gamma(null, e);
            }
            else if (rbt_CH13A11_15points.Checked == true)
            {
                CH13A11_15P_gamma(null, e);
            }
            /*else if (rbt_CH13A11_34points.Checked == true)
            {
                CH13A11_20P_gamma(null, e);
            }*/
            else if (rbt_CH13A11_25points.Checked == true)
            {
                CH13A11_25P_gamma(null, e);
            }
            else if (rbt_CH13A11_19points.Checked == true)
            {
                CH13A11_19P_gamma(null, e);
            }
            else if (rbt_CH13A11_34points.Checked == true)
            {
                CH13A11_34P_gamma(null, e);
            }

        }

        private void 保存gamma绑点配置ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (CH13A11_Gamma_SetBox.Text == string.Empty)
            {
                MessageBox.Show("绑点配置内容为空!");
            }
            else
            {
                //创建保存对话框对象
                SaveFileDialog save = new SaveFileDialog();
                save.Filter = "Code files (*.txt)|*.txt"; //过滤文件类型
                save.FilterIndex = 1;
                save.RestoreDirectory = true;
                if (save.ShowDialog() == DialogResult.OK)
                {
                    string path = save.FileName;
                    save.DefaultExt = ".txt";
                    StreamWriter sw = new StreamWriter(path);
                    sw.WriteLine(CH13A11_Gamma_SetBox.Text);
                    sw.Close();
                }
            }
        }

        private void 载入gamma绑点配置ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog of = new OpenFileDialog();
            of.Filter = "文本文件(*.txt)|*.txt|所有文件(*.*)|*.*";
            of.Title = "载入CH13A11 gamma绑点";

            if (of.ShowDialog() == DialogResult.OK)
            {
                CH13A11_Gamma_SetBox.Clear();
                //读取文本信息
                FileStream fs = new FileStream(of.FileName, FileMode.Open, FileAccess.Read);
                StreamReader streamReader = new StreamReader(fs, Encoding.GetEncoding("GBK"));
                streamReader.BaseStream.Seek(0, SeekOrigin.Begin);
                string str_generate = streamReader.ReadLine();
                //循环读取文本信息
                while (!string.IsNullOrEmpty(str_generate))
                {
                    CH13A11_Gamma_SetBox.AppendText(str_generate + "\r\n");
                    str_generate = streamReader.ReadLine(); //循环读取下一行
                }
                fs.Close(); //关闭流
                streamReader.Close();
            }
        }

        private void CH13A11_15P_gamma(Object myObject, EventArgs e)
        {
            int total_points = Diven_Gamma[0].Points_num;
            double L_X, L_Y, L_Z, lumr, lumg, lumb;
            frmHelp.Msr_CASDK();

            if (Gamma_adjust_timeout_flag == true)//如果是0绑点
            {
                flag1 = 0;
                flag2 = 0;
                flag3 = 0;
            }
            else
            {
                if ((frmHelp.CASDK_LUM < (D_lum[index] + D_lum[index] * Diven_Offset[index].LUM_OFF / 100)) && (frmHelp.CASDK_LUM > (D_lum[index] - D_lum[index] * Diven_Offset[index].LUM_OFF / 100)))//G
                { flag1 = 0; }
                else
                { flag1 = 1; }
                if ((frmHelp.CASDK_x < (Diven_Gamma[0].X + Diven_Offset[index].X_OFF)) && (frmHelp.CASDK_x > (Diven_Gamma[0].X - Diven_Offset[index].X_OFF)) && flag1 == 0)//R
                { flag3 = 0; }
                else
                { flag3 = 1; }
                if ((frmHelp.CASDK_y < (Diven_Gamma[0].Y + Diven_Offset[index].Y_OFF)) && (frmHelp.CASDK_y > (Diven_Gamma[0].Y - Diven_Offset[index].Y_OFF)) && flag1 == 0 && flag3 == 0)//B
                { flag2 = 0; }
                else
                { flag2 = 1; }

            }
            if (flag1 == 0 && flag2 == 0 && flag3 == 0)
            {
                T20.Enabled = false;
                //reset-----
                Gamma_adjust_timeout_flag = false;
                frmHelp.Gamma_auto_adjust_count = 0;
                //--------
                /* if (gamma_227 == true && index == 2)
                 {
                     index = 1; gamma_227 = false;
                 }
                 else
                 {
                     index++;
                 }*/
                //index++;
                if (index == total_points)
                {
                    frmHelp.textBox1.Text = frmHelp.textBox1.Text + "CH13A11 gamma调试完毕!\r\n";
                }
                if (index < total_points)
                {
                    frmHelp.numPatternR.Value = Diven_Offset[index].NO;//固定255灰阶
                    frmHelp.numPatternG.Value = Diven_Offset[index].NO;
                    frmHelp.numPatternB.Value = Diven_Offset[index].NO;

                    Application.DoEvents();
                    frmHelp.OLED_Show_Click(frmHelp.btnPatternW, null);//写入Pattern参数

                    Thread.Sleep(200); //1秒=1000毫秒，
                    frmHelp.Msr_CASDK();
                    T20.Enabled = true;
                    flag1 = 1;
                    flag2 = 1;
                    flag3 = 1;
                }
            }
            else
            {
                decimal r = 0, g = 0, b = 0;
                frmHelp.Gamma_auto_adjust_count_set = 50;

                CaSDKObj.Lvxy_to_XYZ(frmHelp.CASDK_LUM, frmHelp.CASDK_x, frmHelp.CASDK_y, out L_X, out L_Y, out L_Z);
                lumr = L_X;
                lumg = L_Y;
                lumb = L_Z;

                try
                {
                    switch (index)
                    {
                        case 0://14
                            {
                                //frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R14.Value, CH13A11_G14.Value, CH13A11_B14.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R14.Value = r;
                                CH13A11_G14.Value = g;
                                CH13A11_B14.Value = b;



                                /*if (CH13A11_G14.Value <= CH13A11_G13.Value)
                                {
                                    CH13A11_R13.Value = r - 0x10; CH13A11_G13.Value = g - 0x10; CH13A11_B13.Value = b - 0x10;
                                }*/

                            }
                            break;

                        case 1://13
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R13.Value, CH13A11_G13.Value, CH13A11_B13.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R13.Value = r;
                                CH13A11_G13.Value = g;
                                CH13A11_B13.Value = b;
                                CH13A11_R14.Value = CH13A11_R13.Value;
                                CH13A11_G14.Value = CH13A11_G13.Value;
                                CH13A11_B14.Value = CH13A11_B13.Value;

                                if (CH13A11_G13.Value <= CH13A11_G12.Value)
                                {
                                    CH13A11_R12.Value = r - 0x10; CH13A11_G12.Value = g - 0x10; CH13A11_B12.Value = b - 0x10;
                                }
                            }
                            break;

                        case 2://12
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R12.Value, CH13A11_G12.Value, CH13A11_B12.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R12.Value = r;
                                CH13A11_G12.Value = g;
                                CH13A11_B12.Value = b;

                                if (CH13A11_G12.Value <= CH13A11_G11.Value)
                                {
                                    CH13A11_R11.Value = r - 0x10; CH13A11_G11.Value = g - 0x10; CH13A11_B11.Value = b - 0x10;
                                }
                            }
                            break;

                        case 3://111
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R11.Value, CH13A11_G11.Value, CH13A11_B11.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R11.Value = r;
                                CH13A11_G11.Value = g;
                                CH13A11_B11.Value = b;

                                if (CH13A11_G11.Value <= CH13A11_G10.Value)
                                {
                                    CH13A11_R10.Value = r - 0x10; CH13A11_G10.Value = g - 0x10; CH13A11_B10.Value = b - 0x10;
                                }
                            }
                            break;

                        case 4://10
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R10.Value, CH13A11_G10.Value, CH13A11_B10.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R10.Value = r;
                                CH13A11_G10.Value = g;
                                CH13A11_B10.Value = b;

                                if (CH13A11_G10.Value <= CH13A11_G9.Value)
                                {
                                    CH13A11_R9.Value = r - 0x10; CH13A11_G9.Value = g - 0x10; CH13A11_B9.Value = b - 0x10;
                                }
                            }
                            break;

                        case 5://9
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R9.Value, CH13A11_G9.Value, CH13A11_B9.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R9.Value = r;
                                CH13A11_G9.Value = g;
                                CH13A11_B9.Value = b;

                                if (CH13A11_G9.Value <= CH13A11_G8.Value)
                                {
                                    CH13A11_R8.Value = r - 0x10; CH13A11_G8.Value = g - 0x10; CH13A11_B8.Value = b - 0x10;
                                }
                            }
                            break;

                        case 6://8
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R8.Value, CH13A11_G8.Value, CH13A11_B8.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R8.Value = r;
                                CH13A11_G8.Value = g;
                                CH13A11_B8.Value = b;

                                if (CH13A11_G8.Value <= CH13A11_G7.Value)
                                {
                                    CH13A11_R7.Value = r - 0x10; CH13A11_G7.Value = g - 0x10; CH13A11_B7.Value = b - 0x10;
                                }
                            }
                            break;

                        case 7://7
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R7.Value, CH13A11_G7.Value, CH13A11_B7.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R7.Value = r;
                                CH13A11_G7.Value = g;
                                CH13A11_B7.Value = b;

                                if (CH13A11_G7.Value <= CH13A11_G6.Value)
                                {
                                    CH13A11_R6.Value = r - 0x10; CH13A11_G6.Value = g - 0x10; CH13A11_B6.Value = b - 0x10;
                                }
                            }
                            break;
                        case 8://6
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R6.Value, CH13A11_G6.Value, CH13A11_B6.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R6.Value = r;
                                CH13A11_G6.Value = g;
                                CH13A11_B6.Value = b;

                                if (CH13A11_G6.Value <= CH13A11_G5.Value)
                                {
                                    CH13A11_R5.Value = r - 0x10; CH13A11_G5.Value = g - 0x10; CH13A11_B5.Value = b - 0x10;
                                }
                            }
                            break;
                        case 9://5
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R5.Value, CH13A11_G5.Value, CH13A11_B5.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R5.Value = r;
                                CH13A11_G5.Value = g;
                                CH13A11_B5.Value = b;

                                if (CH13A11_G5.Value <= CH13A11_G4.Value)
                                {
                                    CH13A11_R4.Value = r - 0x10; CH13A11_G4.Value = g - 0x10; CH13A11_B4.Value = b - 0x10;
                                }
                            }
                            break;
                        case 10: // // 4
                            {
                                frmHelp.Gamma_auto_adjust_count_set = 30;
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R4.Value, CH13A11_G4.Value, CH13A11_B4.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R4.Value = r;
                                CH13A11_G4.Value = g;
                                CH13A11_B4.Value = b;
                                if (CH13A11_G4.Value <= CH13A11_G3.Value)
                                {
                                    CH13A11_R3.Value = r - 0x10; CH13A11_G3.Value = g - 0x10; CH13A11_B3.Value = b - 0x10;
                                }
                            }
                            break;
                        case 11:  ///3
							{
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R3.Value, CH13A11_G3.Value, CH13A11_B3.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R3.Value = r;
                                CH13A11_G3.Value = g;
                                CH13A11_B3.Value = b;

                                if (CH13A11_G3.Value <= CH13A11_G2.Value)
                                {
                                    CH13A11_R2.Value = r - 0x05; CH13A11_G2.Value = g - 0x05; CH13A11_B2.Value = b - 0x05;
                                }
                            }
                            break;
                        case 12:///2
							{
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R2.Value, CH13A11_G2.Value, CH13A11_B2.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R2.Value = r;
                                CH13A11_G2.Value = g;
                                CH13A11_B2.Value = b;

                                if (CH13A11_G2.Value <= CH13A11_G1.Value)
                                {
                                    CH13A11_R1.Value = r - 0x01; CH13A11_G1.Value = g - 0x01; CH13A11_B1.Value = b - 0x01;
                                }
                            }
                            break;
                        case 13: // 1
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R1.Value, CH13A11_G1.Value, CH13A11_B1.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R1.Value = r;
                                CH13A11_G1.Value = g;
                                CH13A11_B1.Value = b;

                                if (CH13A11_G1.Value <= CH13A11_G0.Value)
                                {
                                    CH13A11_R0.Value = r / 2; CH13A11_G0.Value = g / 2; CH13A11_B0.Value = b / 2;
                                }
                            }
                            break;
                        case 14: // 0
                            {
                                Gamma_adjust_timeout_flag = true;
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R0.Value = 0;
                                CH13A11_G0.Value = 0;
                                CH13A11_B0.Value = 0;
                            }
                            break;

                        default:
                            break;
                    }
                    if (index != 14)
                    {
                        //frmHelp.auto_gamma_write(gamma_r[total_points - 1 - index], Convert.ToUInt16(r), gamma_g[total_points - 1 - index], Convert.ToUInt16(g), gamma_b[total_points - 1 - index], Convert.ToUInt16(b));
                        CH13A11_GammaW_RED_Click(CH13A11_GammaW_RED, null);
                        Thread.Sleep(35);
                        CH13A11_GammaW_RED_Click(CH13A11_GammaW_GREEN, null);
                        Thread.Sleep(35);
                        CH13A11_GammaW_RED_Click(CH13A11_GammaW_BLUE, null);
                        Thread.Sleep(35);
                    }
                    else
                    {
                        CH13A11_GammaW_RED_Click(CH13A11_GammaW_RED, e);
                        Thread.Sleep(35);
                        CH13A11_GammaW_RED_Click(CH13A11_GammaW_GREEN, e);
                        Thread.Sleep(35);
                        CH13A11_GammaW_RED_Click(CH13A11_GammaW_BLUE, e);
                        Thread.Sleep(35);
                        //frmHelp.auto_gamma_write(gamma_r[total_points - 1 - index], 0, gamma_g[total_points - 1 - index], 0, gamma_b[total_points - 1 - index], 0);

                    }
                }
                catch
                {
                    T20.Enabled = false;
                    MessageBox.Show("调整数值超限");
                }
            }
        }
        private void CH13A11_17P_gamma(Object myObject, EventArgs e)
        {
            int total_points = Diven_Gamma[0].Points_num;
            double L_X, L_Y, L_Z, lumr, lumg, lumb;
            frmHelp.Msr_CASDK();

            if (Gamma_adjust_timeout_flag == true)//如果是0绑点
            {
                flag1 = 0;
                flag2 = 0;
                flag3 = 0;
            }
            else
            {
                if ((frmHelp.CASDK_LUM < (D_lum[index] + D_lum[index] * Diven_Offset[index].LUM_OFF / 100)) && (frmHelp.CASDK_LUM > (D_lum[index] - D_lum[index] * Diven_Offset[index].LUM_OFF / 100)))//G
                { flag1 = 0; }
                else
                { flag1 = 1; }
                if ((frmHelp.CASDK_x < (Diven_Gamma[0].X + Diven_Offset[index].X_OFF)) && (frmHelp.CASDK_x > (Diven_Gamma[0].X - Diven_Offset[index].X_OFF)) && flag1 == 0)//R
                { flag3 = 0; }
                else
                { flag3 = 1; }
                if ((frmHelp.CASDK_y < (Diven_Gamma[0].Y + Diven_Offset[index].Y_OFF)) && (frmHelp.CASDK_y > (Diven_Gamma[0].Y - Diven_Offset[index].Y_OFF)) && flag1 == 0 && flag3 == 0)//B
                { flag2 = 0; }
                else
                { flag2 = 1; }

            }
            if (flag1 == 0 && flag2 == 0 && flag3 == 0)
            {
                T20.Enabled = false;
                //reset-----
                Gamma_adjust_timeout_flag = false;
                frmHelp.Gamma_auto_adjust_count = 0;
                //--------
                /* if (gamma_227 == true && index == 3)
                 {
                     index = 2; gamma_227 = false;
                 }
                 else
                 {
                     index++;
                 }*/
                //index++;
                if (index == total_points)
                {
                    frmHelp.textBox1.Text = frmHelp.textBox1.Text + "CH13A11 gamma调试完毕!\r\n";
                }
                if (index < total_points)
                {
                    frmHelp.numPatternR.Value = Diven_Offset[index].NO;//固定255灰阶
                    frmHelp.numPatternG.Value = Diven_Offset[index].NO;
                    frmHelp.numPatternB.Value = Diven_Offset[index].NO;

                    Application.DoEvents();
                    frmHelp.OLED_Show_Click(frmHelp.btnPatternW, null);//写入Pattern参数

                    Thread.Sleep(200); //1秒=1000毫秒，
                    frmHelp.Msr_CASDK();
                    T20.Enabled = true;
                    flag1 = 1;
                    flag2 = 1;
                    flag3 = 1;
                }
            }
            else
            {
                decimal r = 0, g = 0, b = 0;
                frmHelp.Gamma_auto_adjust_count_set = 50;

                CaSDKObj.Lvxy_to_XYZ(frmHelp.CASDK_LUM, frmHelp.CASDK_x, frmHelp.CASDK_y, out L_X, out L_Y, out L_Z);
                lumr = L_X;
                lumg = L_Y;
                lumb = L_Z;

                try
                {
                    switch (index)
                    {
                        case 0://16
                            {
                                //frmHelp.Gamma_auto_adjust_count_set = 75;
                                //frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R16.Value, CH13A11_G16.Value, CH13A11_B16.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R16.Value = r;
                                CH13A11_G16.Value = g;
                                CH13A11_B16.Value = b;

                                /*if (CH13A11_G16.Value <= CH13A11_G15.Value)
                                {
                                    CH13A11_R15.Value = r - 0x10; CH13A11_G15.Value = g - 0x10; CH13A11_B15.Value = b - 0x10;
                                }*/

                            }
                            break;

                        case 1://15
                            {
                                /* frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R15.Value, CH13A11_G15.Value, CH13A11_B15.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)*/
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R15.Value = r;
                                CH13A11_G15.Value = g;
                                CH13A11_B15.Value = b;
                                /*if (CH13A11_G15.Value <= CH13A11_G14.Value)
                                 {
                                     CH13A11_R14.Value = r - 0x10; CH13A11_G14.Value = g - 0x10; CH13A11_B14.Value = b - 0x10;
                                 }*/

                            }
                            break;

                        case 2://14
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R14.Value, CH13A11_G14.Value, CH13A11_B14.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R14.Value = r;
                                CH13A11_G14.Value = g;
                                CH13A11_B14.Value = b;
                                CH13A11_R16.Value = CH13A11_R14.Value;
                                CH13A11_G16.Value = CH13A11_G14.Value;
                                CH13A11_B16.Value = CH13A11_B14.Value;
                                CH13A11_R15.Value = CH13A11_R14.Value;
                                CH13A11_G15.Value = CH13A11_G14.Value;
                                CH13A11_B15.Value = CH13A11_B14.Value;

                                if (CH13A11_G14.Value <= CH13A11_G13.Value)
                                {
                                    CH13A11_R13.Value = r - 0x10; CH13A11_G13.Value = g - 0x10; CH13A11_B13.Value = b - 0x10;
                                }

                            }
                            break;

                        case 3://13
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R13.Value, CH13A11_G13.Value, CH13A11_B13.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R13.Value = r;
                                CH13A11_G13.Value = g;
                                CH13A11_B13.Value = b;

                                if (CH13A11_G13.Value <= CH13A11_G12.Value)
                                {
                                    CH13A11_R12.Value = r - 0x10; CH13A11_G12.Value = g - 0x10; CH13A11_B12.Value = b - 0x10;
                                }
                            }
                            break;

                        case 4://12
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R12.Value, CH13A11_G12.Value, CH13A11_B12.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R12.Value = r;
                                CH13A11_G12.Value = g;
                                CH13A11_B12.Value = b;

                                if (CH13A11_G12.Value <= CH13A11_G11.Value)
                                {
                                    CH13A11_R11.Value = r - 0x10; CH13A11_G11.Value = g - 0x10; CH13A11_B11.Value = b - 0x10;
                                }
                            }
                            break;

                        case 5://111
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R11.Value, CH13A11_G11.Value, CH13A11_B11.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R11.Value = r;
                                CH13A11_G11.Value = g;
                                CH13A11_B11.Value = b;

                                if (CH13A11_G11.Value <= CH13A11_G10.Value)
                                {
                                    CH13A11_R10.Value = r - 0x10; CH13A11_G10.Value = g - 0x10; CH13A11_B10.Value = b - 0x10;
                                }
                            }
                            break;

                        case 6://10
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R10.Value, CH13A11_G10.Value, CH13A11_B10.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R10.Value = r;
                                CH13A11_G10.Value = g;
                                CH13A11_B10.Value = b;

                                if (CH13A11_G10.Value <= CH13A11_G9.Value)
                                {
                                    CH13A11_R9.Value = r - 0x10; CH13A11_G9.Value = g - 0x10; CH13A11_B9.Value = b - 0x10;
                                }
                            }
                            break;

                        case 7://9
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R9.Value, CH13A11_G9.Value, CH13A11_B9.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R9.Value = r;
                                CH13A11_G9.Value = g;
                                CH13A11_B9.Value = b;

                                if (CH13A11_G9.Value <= CH13A11_G8.Value)
                                {
                                    CH13A11_R8.Value = r - 0x10; CH13A11_G8.Value = g - 0x10; CH13A11_B8.Value = b - 0x10;
                                }
                            }
                            break;

                        case 8://8
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R8.Value, CH13A11_G8.Value, CH13A11_B8.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R8.Value = r;
                                CH13A11_G8.Value = g;
                                CH13A11_B8.Value = b;

                                if (CH13A11_G8.Value <= CH13A11_G7.Value)
                                {
                                    CH13A11_R7.Value = r - 0x10; CH13A11_G7.Value = g - 0x10; CH13A11_B7.Value = b - 0x10;
                                }
                            }
                            break;

                        case 9://7
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R7.Value, CH13A11_G7.Value, CH13A11_B7.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R7.Value = r;
                                CH13A11_G7.Value = g;
                                CH13A11_B7.Value = b;

                                if (CH13A11_G7.Value <= CH13A11_G6.Value)
                                {
                                    CH13A11_R6.Value = r - 0x10; CH13A11_G6.Value = g - 0x10; CH13A11_B6.Value = b - 0x10;
                                }
                            }
                            break;
                        case 10://6
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R6.Value, CH13A11_G6.Value, CH13A11_B6.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R6.Value = r;
                                CH13A11_G6.Value = g;
                                CH13A11_B6.Value = b;

                                if (CH13A11_G6.Value <= CH13A11_G5.Value)
                                {
                                    CH13A11_R5.Value = r - 0x10; CH13A11_G5.Value = g - 0x10; CH13A11_B5.Value = b - 0x10;
                                }
                            }
                            break;
                        case 11://5
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R5.Value, CH13A11_G5.Value, CH13A11_B5.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R5.Value = r;
                                CH13A11_G5.Value = g;
                                CH13A11_B5.Value = b;

                                if (CH13A11_G5.Value <= CH13A11_G4.Value)
                                {
                                    CH13A11_R4.Value = r - 0x10; CH13A11_G4.Value = g - 0x10; CH13A11_B4.Value = b - 0x10;
                                }
                            }
                            break;
                        case 12: // // 4
                            {
                                frmHelp.Gamma_auto_adjust_count_set = 30;
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R4.Value, CH13A11_G4.Value, CH13A11_B4.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R4.Value = r;
                                CH13A11_G4.Value = g;
                                CH13A11_B4.Value = b;
                                if (CH13A11_G4.Value <= CH13A11_G3.Value)
                                {
                                    CH13A11_R3.Value = r - 0x10; CH13A11_G3.Value = g - 0x10; CH13A11_B3.Value = b - 0x10;
                                }
                            }
                            break;
                        case 13:  ///3
							{
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R3.Value, CH13A11_G3.Value, CH13A11_B3.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R3.Value = r;
                                CH13A11_G3.Value = g;
                                CH13A11_B3.Value = b;

                                if (CH13A11_G3.Value <= CH13A11_G2.Value)
                                {
                                    CH13A11_R2.Value = r - 0x05; CH13A11_G2.Value = g - 0x05; CH13A11_B2.Value = b - 0x05;
                                }
                            }
                            break;
                        case 14:///2
							{
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R2.Value, CH13A11_G2.Value, CH13A11_B2.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R2.Value = r;
                                CH13A11_G2.Value = g;
                                CH13A11_B2.Value = b;

                                if (CH13A11_G2.Value <= CH13A11_G1.Value)
                                {
                                    CH13A11_R1.Value = r - 0x01; CH13A11_G1.Value = g - 0x01; CH13A11_B1.Value = b - 0x01;
                                }
                            }
                            break;
                        case 15: // 1
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R1.Value, CH13A11_G1.Value, CH13A11_B1.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R1.Value = r;
                                CH13A11_G1.Value = g;
                                CH13A11_B1.Value = b;

                                if (CH13A11_G1.Value <= CH13A11_G0.Value)
                                {
                                    CH13A11_R0.Value = r / 2; CH13A11_G0.Value = g / 2; CH13A11_B0.Value = b / 2;
                                }
                            }
                            break;
                        case 16: // 0
                            {
                                Gamma_adjust_timeout_flag = true;
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R0.Value = 0;
                                CH13A11_G0.Value = 0;
                                CH13A11_B0.Value = 0;
                            }
                            break;

                        default:
                            break;
                    }
                    if (index != 16)
                    {
                        //frmHelp.auto_gamma_write(gamma_r[total_points - 1 - index], Convert.ToUInt16(r), gamma_g[total_points - 1 - index], Convert.ToUInt16(g), gamma_b[total_points - 1 - index], Convert.ToUInt16(b));
                        CH13A11_GammaW_RED_Click(CH13A11_GammaW_RED, null);
                        Thread.Sleep(35);
                        CH13A11_GammaW_RED_Click(CH13A11_GammaW_GREEN, null);
                        Thread.Sleep(35);
                        CH13A11_GammaW_RED_Click(CH13A11_GammaW_BLUE, null);
                        Thread.Sleep(35);
                    }
                    else
                    {
                        CH13A11_GammaW_RED_Click(CH13A11_GammaW_RED, e);
                        Thread.Sleep(35);
                        CH13A11_GammaW_RED_Click(CH13A11_GammaW_GREEN, e);
                        Thread.Sleep(35);
                        CH13A11_GammaW_RED_Click(CH13A11_GammaW_BLUE, e);
                        Thread.Sleep(35);
                        //frmHelp.auto_gamma_write(gamma_r[total_points - 1 - index], 0, gamma_g[total_points - 1 - index], 0, gamma_b[total_points - 1 - index], 0);

                    }
                }
                catch
                {
                    T20.Enabled = false;
                    MessageBox.Show("调整数值超限");
                }
            }
        }
        private void CH13A11_19P_gamma(Object myObject, EventArgs e)
        {
            int total_points = Diven_Gamma[0].Points_num;
            double L_X, L_Y, L_Z, lumr, lumg, lumb;
            frmHelp.Msr_CASDK();

            if (Gamma_adjust_timeout_flag == true)//如果是0绑点
            {
                flag1 = 0;
                flag2 = 0;
                flag3 = 0;
            }
            else
            {
                if ((frmHelp.CASDK_LUM < (D_lum[index] + D_lum[index] * Diven_Offset[index].LUM_OFF / 100)) && (frmHelp.CASDK_LUM > (D_lum[index] - D_lum[index] * Diven_Offset[index].LUM_OFF / 100)))//G
                { flag1 = 0; }
                else
                { flag1 = 1; }
                if ((frmHelp.CASDK_x < (Diven_Gamma[0].X + Diven_Offset[index].X_OFF)) && (frmHelp.CASDK_x > (Diven_Gamma[0].X - Diven_Offset[index].X_OFF)) && flag1 == 0)//R
                { flag3 = 0; }
                else
                { flag3 = 1; }
                if ((frmHelp.CASDK_y < (Diven_Gamma[0].Y + Diven_Offset[index].Y_OFF)) && (frmHelp.CASDK_y > (Diven_Gamma[0].Y - Diven_Offset[index].Y_OFF)) && flag1 == 0 && flag3 == 0)//B
                { flag2 = 0; }
                else
                { flag2 = 1; }

            }
            if (flag1 == 0 && flag2 == 0 && flag3 == 0)
            {
                T20.Enabled = false;
                //reset-----
                Gamma_adjust_timeout_flag = false;
                frmHelp.Gamma_auto_adjust_count = 0;
                //--------
                /* if (gamma_227 == true && index == 2)
                 {
                     index = 1; gamma_227 = false;
                 }
                 else
                 {
                     index++;
                 }*/
                //index++;
                if (index == total_points)
                {
                    frmHelp.textBox1.Text = frmHelp.textBox1.Text + "CH13A11 gamma调试完毕!\r\n";
                }
                if (index < total_points)
                {
                    frmHelp.numPatternR.Value = Diven_Offset[index].NO;//固定255灰阶
                    frmHelp.numPatternG.Value = Diven_Offset[index].NO;
                    frmHelp.numPatternB.Value = Diven_Offset[index].NO;

                    Application.DoEvents();
                    frmHelp.OLED_Show_Click(frmHelp.btnPatternW, null);//写入Pattern参数

                    Thread.Sleep(200); //1秒=1000毫秒，
                    frmHelp.Msr_CASDK();
                    T20.Enabled = true;
                    flag1 = 1;
                    flag2 = 1;
                    flag3 = 1;
                }
            }
            else
            {
                decimal r = 0, g = 0, b = 0;
                frmHelp.Gamma_auto_adjust_count_set = 50;

                CaSDKObj.Lvxy_to_XYZ(frmHelp.CASDK_LUM, frmHelp.CASDK_x, frmHelp.CASDK_y, out L_X, out L_Y, out L_Z);
                lumr = L_X;
                lumg = L_Y;
                lumb = L_Z;

                try
                {
                    switch (index)
                    {
                        case 0://16
                            {
                                //frmHelp.Gamma_auto_adjust_count_set = 75;
                                //frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R16.Value, CH13A11_G16.Value, CH13A11_B16.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R18.Value = r;
                                CH13A11_G18.Value = g;
                                CH13A11_B18.Value = b;

                                /*if (CH13A11_G16.Value <= CH13A11_G15.Value)
                                {
                                    CH13A11_R15.Value = r - 0x10; CH13A11_G15.Value = g - 0x10; CH13A11_B15.Value = b - 0x10;
                                }*/

                            }
                            break;


                        case 1://16
                            {
                                frmHelp.Gamma_auto_adjust_count_set = 75;
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R17.Value, CH13A11_G17.Value, CH13A11_B17.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R17.Value = r;
                                CH13A11_G17.Value = g;
                                CH13A11_B17.Value = b;
                                CH13A11_R18.Value = CH13A11_R17.Value;
                                CH13A11_G18.Value = CH13A11_G17.Value;
                                CH13A11_B18.Value = CH13A11_B17.Value;

                                if (CH13A11_G17.Value <= CH13A11_G16.Value)
                                {
                                    CH13A11_R16.Value = r - 0x10; CH13A11_G16.Value = g - 0x10; CH13A11_B16.Value = b - 0x10;
                                }

                            }
                            break;
                        case 2://16
                            {
                                frmHelp.Gamma_auto_adjust_count_set = 75;
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R16.Value, CH13A11_G16.Value, CH13A11_B16.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R16.Value = r;
                                CH13A11_G16.Value = g;
                                CH13A11_B16.Value = b;

                                if (CH13A11_G16.Value <= CH13A11_G15.Value)
                                {
                                    CH13A11_R15.Value = r - 0x10; CH13A11_G15.Value = g - 0x10; CH13A11_B15.Value = b - 0x10;
                                }

                            }
                            break;



                        case 3://15
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R15.Value, CH13A11_G15.Value, CH13A11_B15.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R15.Value = r;
                                CH13A11_G15.Value = g;
                                CH13A11_B15.Value = b;
                                if (CH13A11_G15.Value <= CH13A11_G14.Value)
                                {
                                    CH13A11_R14.Value = r - 0x10; CH13A11_G14.Value = g - 0x10; CH13A11_B14.Value = b - 0x10;
                                }

                            }
                            break;

                        case 4://14
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R14.Value, CH13A11_G14.Value, CH13A11_B14.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R14.Value = r;
                                CH13A11_G14.Value = g;
                                CH13A11_B14.Value = b;

                                if (CH13A11_G14.Value <= CH13A11_G13.Value)
                                {
                                    CH13A11_R13.Value = r - 0x10; CH13A11_G13.Value = g - 0x10; CH13A11_B13.Value = b - 0x10;
                                }

                            }
                            break;

                        case 5://13
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R13.Value, CH13A11_G13.Value, CH13A11_B13.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R13.Value = r;
                                CH13A11_G13.Value = g;
                                CH13A11_B13.Value = b;

                                if (CH13A11_G13.Value <= CH13A11_G12.Value)
                                {
                                    CH13A11_R12.Value = r - 0x10; CH13A11_G12.Value = g - 0x10; CH13A11_B12.Value = b - 0x10;
                                }
                            }
                            break;

                        case 6://12
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R12.Value, CH13A11_G12.Value, CH13A11_B12.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R12.Value = r;
                                CH13A11_G12.Value = g;
                                CH13A11_B12.Value = b;

                                if (CH13A11_G12.Value <= CH13A11_G11.Value)
                                {
                                    CH13A11_R11.Value = r - 0x10; CH13A11_G11.Value = g - 0x10; CH13A11_B11.Value = b - 0x10;
                                }
                            }
                            break;

                        case 7://111
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R11.Value, CH13A11_G11.Value, CH13A11_B11.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R11.Value = r;
                                CH13A11_G11.Value = g;
                                CH13A11_B11.Value = b;

                                if (CH13A11_G11.Value <= CH13A11_G10.Value)
                                {
                                    CH13A11_R10.Value = r - 0x10; CH13A11_G10.Value = g - 0x10; CH13A11_B10.Value = b - 0x10;
                                }
                            }
                            break;

                        case 8://10
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R10.Value, CH13A11_G10.Value, CH13A11_B10.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R10.Value = r;
                                CH13A11_G10.Value = g;
                                CH13A11_B10.Value = b;

                                if (CH13A11_G10.Value <= CH13A11_G9.Value)
                                {
                                    CH13A11_R9.Value = r - 0x10; CH13A11_G9.Value = g - 0x10; CH13A11_B9.Value = b - 0x10;
                                }
                            }
                            break;

                        case 9://9
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R9.Value, CH13A11_G9.Value, CH13A11_B9.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R9.Value = r;
                                CH13A11_G9.Value = g;
                                CH13A11_B9.Value = b;

                                if (CH13A11_G9.Value <= CH13A11_G8.Value)
                                {
                                    CH13A11_R8.Value = r - 0x10; CH13A11_G8.Value = g - 0x10; CH13A11_B8.Value = b - 0x10;
                                }
                            }
                            break;

                        case 10://8
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R8.Value, CH13A11_G8.Value, CH13A11_B8.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R8.Value = r;
                                CH13A11_G8.Value = g;
                                CH13A11_B8.Value = b;

                                if (CH13A11_G8.Value <= CH13A11_G7.Value)
                                {
                                    CH13A11_R7.Value = r - 0x10; CH13A11_G7.Value = g - 0x10; CH13A11_B7.Value = b - 0x10;
                                }
                            }
                            break;

                        case 11://7
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R7.Value, CH13A11_G7.Value, CH13A11_B7.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R7.Value = r;
                                CH13A11_G7.Value = g;
                                CH13A11_B7.Value = b;

                                if (CH13A11_G7.Value <= CH13A11_G6.Value)
                                {
                                    CH13A11_R6.Value = r - 0x10; CH13A11_G6.Value = g - 0x10; CH13A11_B6.Value = b - 0x10;
                                }
                            }
                            break;
                        case 12://6
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R6.Value, CH13A11_G6.Value, CH13A11_B6.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R6.Value = r;
                                CH13A11_G6.Value = g;
                                CH13A11_B6.Value = b;

                                if (CH13A11_G6.Value <= CH13A11_G5.Value)
                                {
                                    CH13A11_R5.Value = r - 0x10; CH13A11_G5.Value = g - 0x10; CH13A11_B5.Value = b - 0x10;
                                }
                            }
                            break;
                        case 13://5
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R5.Value, CH13A11_G5.Value, CH13A11_B5.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R5.Value = r;
                                CH13A11_G5.Value = g;
                                CH13A11_B5.Value = b;

                                if (CH13A11_G5.Value <= CH13A11_G4.Value)
                                {
                                    CH13A11_R4.Value = r - 0x10; CH13A11_G4.Value = g - 0x10; CH13A11_B4.Value = b - 0x10;
                                }
                            }
                            break;
                        case 14: // // 4
                            {
                                frmHelp.Gamma_auto_adjust_count_set = 30;
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R4.Value, CH13A11_G4.Value, CH13A11_B4.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R4.Value = r;
                                CH13A11_G4.Value = g;
                                CH13A11_B4.Value = b;
                                if (CH13A11_G4.Value <= CH13A11_G3.Value)
                                {
                                    CH13A11_R3.Value = r - 0x10; CH13A11_G3.Value = g - 0x10; CH13A11_B3.Value = b - 0x10;
                                }
                            }
                            break;
                        case 15:  ///3
							{
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R3.Value, CH13A11_G3.Value, CH13A11_B3.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R3.Value = r;
                                CH13A11_G3.Value = g;
                                CH13A11_B3.Value = b;

                                if (CH13A11_G3.Value <= CH13A11_G2.Value)
                                {
                                    CH13A11_R2.Value = r - 0x05; CH13A11_G2.Value = g - 0x05; CH13A11_B2.Value = b - 0x05;
                                }
                            }
                            break;
                        case 16:///2
							{
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R2.Value, CH13A11_G2.Value, CH13A11_B2.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R2.Value = r;
                                CH13A11_G2.Value = g;
                                CH13A11_B2.Value = b;

                                if (CH13A11_G2.Value <= CH13A11_G1.Value)
                                {
                                    CH13A11_R1.Value = r - 0x01; CH13A11_G1.Value = g - 0x01; CH13A11_B1.Value = b - 0x01;
                                }
                            }
                            break;
                        case 17: // 1
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R1.Value, CH13A11_G1.Value, CH13A11_B1.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R1.Value = r;
                                CH13A11_G1.Value = g;
                                CH13A11_B1.Value = b;

                                if (CH13A11_G1.Value <= CH13A11_G0.Value)
                                {
                                    CH13A11_R0.Value = r / 2; CH13A11_G0.Value = g / 2; CH13A11_B0.Value = b / 2;
                                }
                            }
                            break;
                        case 18: // 0
                            {
                                Gamma_adjust_timeout_flag = true;
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R0.Value = 0;
                                CH13A11_G0.Value = 0;
                                CH13A11_B0.Value = 0;
                            }
                            break;

                        default:
                            break;
                    }
                    if (index != 18)
                    {
                        //frmHelp.auto_gamma_write(gamma_r[total_points - 1 - index], Convert.ToUInt16(r), gamma_g[total_points - 1 - index], Convert.ToUInt16(g), gamma_b[total_points - 1 - index], Convert.ToUInt16(b));
                        CH13A11_GammaW_RED_Click(CH13A11_GammaW_RED, null);
                        Thread.Sleep(35);
                        CH13A11_GammaW_RED_Click(CH13A11_GammaW_GREEN, null);
                        Thread.Sleep(35);
                        CH13A11_GammaW_RED_Click(CH13A11_GammaW_BLUE, null);
                        Thread.Sleep(35);
                    }
                    else
                    {
                        CH13A11_GammaW_RED_Click(CH13A11_GammaW_RED, e);
                        Thread.Sleep(35);
                        CH13A11_GammaW_RED_Click(CH13A11_GammaW_GREEN, e);
                        Thread.Sleep(35);
                        CH13A11_GammaW_RED_Click(CH13A11_GammaW_BLUE, e);
                        Thread.Sleep(35);
                        //frmHelp.auto_gamma_write(gamma_r[total_points - 1 - index], 0, gamma_g[total_points - 1 - index], 0, gamma_b[total_points - 1 - index], 0);

                    }
                }
                catch
                {
                    T20.Enabled = false;
                    MessageBox.Show("调整数值超限");
                }
            }
        }
        private void CH13A11_20P_gamma(Object myObject, EventArgs e)
        {
            int total_points = Diven_Gamma[0].Points_num;
            double L_X, L_Y, L_Z, lumr, lumg, lumb;

            frmHelp.Msr_CASDK();



            if (Gamma_adjust_timeout_flag == true)//如果是0绑点
            {
                flag1 = 0;
                flag2 = 0;
                flag3 = 0;
            }
            else
            {
                if ((frmHelp.CASDK_LUM < (D_lum[index] + D_lum[index] * Diven_Offset[index].LUM_OFF / 100)) && (frmHelp.CASDK_LUM > (D_lum[index] - D_lum[index] * Diven_Offset[index].LUM_OFF / 100)))//G
                { flag1 = 0; }
                else
                { flag1 = 1; }
                if ((frmHelp.CASDK_x < (Diven_Gamma[0].X + Diven_Offset[index].X_OFF)) && (frmHelp.CASDK_x > (Diven_Gamma[0].X - Diven_Offset[index].X_OFF)) && flag1 == 0)//R
                { flag3 = 0; }
                else
                { flag3 = 1; }
                if ((frmHelp.CASDK_y < (Diven_Gamma[0].Y + Diven_Offset[index].Y_OFF)) && (frmHelp.CASDK_y > (Diven_Gamma[0].Y - Diven_Offset[index].Y_OFF)) && flag1 == 0 && flag3 == 0)//B
                { flag2 = 0; }
                else
                { flag2 = 1; }

            }
            if (flag1 == 0 && flag2 == 0 && flag3 == 0)
            {
                T20.Enabled = false;
                //reset-----
                Gamma_adjust_timeout_flag = false;
                frmHelp.Gamma_auto_adjust_count = 0;
                //--------
                /*if (gamma_227 == true && index == 3)
                {
                    index = 2; gamma_227 = false;
                }
                else
                {
                    index++;
                }*/
                if (index == total_points)
                {
                    frmHelp.textBox1.Text = frmHelp.textBox1.Text + "CH13A11 gamma调试完毕!\r\n";
                }
                if (index < total_points)
                {
                    frmHelp.numPatternR.Value = Diven_Offset[index].NO;//固定255灰阶
                    frmHelp.numPatternG.Value = Diven_Offset[index].NO;
                    frmHelp.numPatternB.Value = Diven_Offset[index].NO;

                    Application.DoEvents();
                    frmHelp.OLED_Show_Click(frmHelp.btnPatternW, null);//写入Pattern参数

                    Thread.Sleep(200); //1秒=1000毫秒，
                    frmHelp.Msr_CASDK();
                    T20.Enabled = true;
                    flag1 = 1;
                    flag2 = 1;
                    flag3 = 1;
                }
            }
            else
            {
                decimal r = 0, g = 0, b = 0;
                frmHelp.Gamma_auto_adjust_count_set = 50;

                CaSDKObj.Lvxy_to_XYZ(frmHelp.CASDK_LUM, frmHelp.CASDK_x, frmHelp.CASDK_y, out L_X, out L_Y, out L_Z);
                lumr = L_X;
                lumg = L_Y;
                lumb = L_Z;

                try
                {
                    switch (index)
                    {
                        case 0://20
                            {
                                //frmHelp.Gamma_auto_adjust_count_set = 75;
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R19.Value, CH13A11_G19.Value, CH13A11_B19.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R19.Value = r;
                                CH13A11_G19.Value = g;
                                CH13A11_B19.Value = b;

                                if (CH13A11_G19.Value <= CH13A11_G18.Value)
                                {
                                    CH13A11_R18.Value = r - 0x10; CH13A11_G18.Value = g - 0x10; CH13A11_B18.Value = b - 0x10;
                                }
                            }
                            break;

                        case 1:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R18.Value, CH13A11_G18.Value, CH13A11_B18.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R18.Value = r;
                                CH13A11_G18.Value = g;
                                CH13A11_B18.Value = b;

                                if (CH13A11_G18.Value <= CH13A11_G17.Value)
                                {
                                    CH13A11_R17.Value = r - 0x10; CH13A11_G17.Value = g - 0x10; CH13A11_B17.Value = b - 0x10;
                                }
                            }
                            break;
                        case 2:
                            {
                                frmHelp.Gamma_auto_adjust_count_set = 75;
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R17.Value, CH13A11_G17.Value, CH13A11_B17.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R17.Value = r;
                                CH13A11_G17.Value = g;
                                CH13A11_B17.Value = b;
                                CH13A11_R18.Value = CH13A11_R17.Value;
                                CH13A11_G18.Value = CH13A11_G17.Value;
                                CH13A11_B18.Value = CH13A11_B17.Value;
                                CH13A11_R19.Value = CH13A11_R17.Value;
                                CH13A11_G19.Value = CH13A11_G17.Value;
                                CH13A11_B19.Value = CH13A11_B17.Value;


                                if (CH13A11_G16.Value <= CH13A11_G15.Value)
                                {
                                    CH13A11_R15.Value = r - 0x10; CH13A11_G15.Value = g - 0x10; CH13A11_B15.Value = b - 0x10;
                                }

                            }
                            break;
                        case 3:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R16.Value, CH13A11_G16.Value, CH13A11_B16.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R16.Value = r;
                                CH13A11_G16.Value = g;
                                CH13A11_B16.Value = b;

                                if (CH13A11_G16.Value <= CH13A11_G15.Value)
                                {
                                    CH13A11_R15.Value = r - 0x10; CH13A11_G15.Value = g - 0x10; CH13A11_B15.Value = b - 0x10;
                                }

                            }
                            break;

                        case 4:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R15.Value, CH13A11_G15.Value, CH13A11_B15.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R15.Value = r;
                                CH13A11_G15.Value = g;
                                CH13A11_B15.Value = b;

                                if (CH13A11_G15.Value <= CH13A11_G14.Value)
                                {
                                    CH13A11_R14.Value = r - 0x10; CH13A11_G14.Value = g - 0x10; CH13A11_B14.Value = b - 0x10;
                                }

                            }
                            break;

                        case 5://14
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R14.Value, CH13A11_G14.Value, CH13A11_B14.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R14.Value = r;
                                CH13A11_G14.Value = g;
                                CH13A11_B14.Value = b;

                                if (CH13A11_G14.Value <= CH13A11_G13.Value)
                                {
                                    CH13A11_R13.Value = r - 0x10; CH13A11_G13.Value = g - 0x10; CH13A11_B13.Value = b - 0x10;
                                }

                            }
                            break;

                        case 6://13
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R13.Value, CH13A11_G13.Value, CH13A11_B13.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R13.Value = r;
                                CH13A11_G13.Value = g;
                                CH13A11_B13.Value = b;

                                if (CH13A11_G13.Value <= CH13A11_G12.Value)
                                {
                                    CH13A11_R12.Value = r - 0x10; CH13A11_G12.Value = g - 0x10; CH13A11_B12.Value = b - 0x10;
                                }
                            }
                            break;

                        case 7://12
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R12.Value, CH13A11_G12.Value, CH13A11_B12.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R12.Value = r;
                                CH13A11_G12.Value = g;
                                CH13A11_B12.Value = b;

                                if (CH13A11_G12.Value <= CH13A11_G11.Value)
                                {
                                    CH13A11_R11.Value = r - 0x10; CH13A11_G11.Value = g - 0x10; CH13A11_B11.Value = b - 0x10;
                                }
                            }
                            break;

                        case 8://111
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R11.Value, CH13A11_G11.Value, CH13A11_B11.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R11.Value = r;
                                CH13A11_G11.Value = g;
                                CH13A11_B11.Value = b;

                                if (CH13A11_G11.Value <= CH13A11_G10.Value)
                                {
                                    CH13A11_R10.Value = r - 0x10; CH13A11_G10.Value = g - 0x10; CH13A11_B10.Value = b - 0x10;
                                }
                            }
                            break;

                        case 9://10
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R10.Value, CH13A11_G10.Value, CH13A11_B10.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R10.Value = r;
                                CH13A11_G10.Value = g;
                                CH13A11_B10.Value = b;

                                if (CH13A11_G10.Value <= CH13A11_G9.Value)
                                {
                                    CH13A11_R9.Value = r - 0x10; CH13A11_G9.Value = g - 0x10; CH13A11_B9.Value = b - 0x10;
                                }
                            }
                            break;

                        case 10://9
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R9.Value, CH13A11_G9.Value, CH13A11_B9.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R9.Value = r;
                                CH13A11_G9.Value = g;
                                CH13A11_B9.Value = b;

                                if (CH13A11_G9.Value <= CH13A11_G8.Value)
                                {
                                    CH13A11_R8.Value = r - 0x10; CH13A11_G8.Value = g - 0x10; CH13A11_B8.Value = b - 0x10;
                                }
                            }
                            break;

                        case 11://8
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R8.Value, CH13A11_G8.Value, CH13A11_B8.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R8.Value = r;
                                CH13A11_G8.Value = g;
                                CH13A11_B8.Value = b;

                                if (CH13A11_G8.Value <= CH13A11_G7.Value)
                                {
                                    CH13A11_R7.Value = r - 0x10; CH13A11_G7.Value = g - 0x10; CH13A11_B7.Value = b - 0x10;
                                }
                            }
                            break;

                        case 12://7
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R7.Value, CH13A11_G7.Value, CH13A11_B7.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R7.Value = r;
                                CH13A11_G7.Value = g;
                                CH13A11_B7.Value = b;

                                if (CH13A11_G7.Value <= CH13A11_G6.Value)
                                {
                                    CH13A11_R6.Value = r - 0x10; CH13A11_G6.Value = g - 0x10; CH13A11_B6.Value = b - 0x10;
                                }
                            }
                            break;
                        case 13://6
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R6.Value, CH13A11_G6.Value, CH13A11_B6.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R6.Value = r;
                                CH13A11_G6.Value = g;
                                CH13A11_B6.Value = b;

                                if (CH13A11_G6.Value <= CH13A11_G5.Value)
                                {
                                    CH13A11_R5.Value = r - 0x10; CH13A11_G5.Value = g - 0x10; CH13A11_B5.Value = b - 0x10;
                                }
                            }
                            break;
                        case 14://5
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R5.Value, CH13A11_G5.Value, CH13A11_B5.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R5.Value = r;
                                CH13A11_G5.Value = g;
                                CH13A11_B5.Value = b;

                                if (CH13A11_G5.Value <= CH13A11_G4.Value)
                                {
                                    CH13A11_R4.Value = r - 0x10; CH13A11_G4.Value = g - 0x10; CH13A11_B4.Value = b - 0x10;
                                }
                            }
                            break;
                        case 15: // // 4
                            {
                                frmHelp.Gamma_auto_adjust_count_set = 30;
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R4.Value, CH13A11_G4.Value, CH13A11_B4.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R4.Value = r;
                                CH13A11_G4.Value = g;
                                CH13A11_B4.Value = b;
                                if (CH13A11_G4.Value <= CH13A11_G3.Value)
                                {
                                    CH13A11_R3.Value = r - 0x10; CH13A11_G3.Value = g - 0x10; CH13A11_B3.Value = b - 0x10;
                                }
                            }
                            break;
                        case 16:  ///3
							{
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R3.Value, CH13A11_G3.Value, CH13A11_B3.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R3.Value = r;
                                CH13A11_G3.Value = g;
                                CH13A11_B3.Value = b;

                                if (CH13A11_G3.Value <= CH13A11_G2.Value)
                                {
                                    CH13A11_R2.Value = r - 0x05; CH13A11_G2.Value = g - 0x05; CH13A11_B2.Value = b - 0x05;
                                }
                            }
                            break;
                        case 17:///2
							{
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R2.Value, CH13A11_G2.Value, CH13A11_B2.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R2.Value = r;
                                CH13A11_G2.Value = g;
                                CH13A11_B2.Value = b;

                                if (CH13A11_G2.Value <= CH13A11_G1.Value)
                                {
                                    CH13A11_R1.Value = r - 0x01; CH13A11_G1.Value = g - 0x01; CH13A11_B1.Value = b - 0x01;
                                }
                            }
                            break;
                        case 18: // 1
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R1.Value, CH13A11_G1.Value, CH13A11_B1.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R1.Value = r;
                                CH13A11_G1.Value = g;
                                CH13A11_B1.Value = b;

                                if (CH13A11_G1.Value <= CH13A11_G0.Value)
                                {
                                    CH13A11_R0.Value = r - 0x01; CH13A11_G0.Value = g - 0x01; CH13A11_B0.Value = b - 0x01;
                                }
                            }
                            break;
                        case 19: // 0
                            {
                                Gamma_adjust_timeout_flag = true;
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R0.Value = 0;
                                CH13A11_G0.Value = 0;
                                CH13A11_B0.Value = 0;
                            }
                            break;

                        default:
                            break;
                    }
                    if (index != 19)
                    {
                        //frmHelp.auto_gamma_write(gamma_r[total_points - 1 - index], Convert.ToUInt16(r), gamma_g[total_points - 1 - index], Convert.ToUInt16(g), gamma_b[total_points - 1 - index], Convert.ToUInt16(b));
                        CH13A11_GammaW_RED_Click(CH13A11_GammaW_RED, null);
                        Thread.Sleep(35);
                        CH13A11_GammaW_RED_Click(CH13A11_GammaW_GREEN, null);
                        Thread.Sleep(35);
                        CH13A11_GammaW_RED_Click(CH13A11_GammaW_BLUE, null);
                        Thread.Sleep(35);
                    }
                    else
                    {
                        CH13A11_GammaW_RED_Click(CH13A11_GammaW_RED, e);
                        Thread.Sleep(35);
                        CH13A11_GammaW_RED_Click(CH13A11_GammaW_GREEN, e);
                        Thread.Sleep(35);
                        CH13A11_GammaW_RED_Click(CH13A11_GammaW_BLUE, e);
                        Thread.Sleep(35);
                        //frmHelp.auto_gamma_write(gamma_r[total_points - 1 - index], 0, gamma_g[total_points - 1 - index], 0, gamma_b[total_points - 1 - index], 0);

                    }
                }
                catch
                {
                    T20.Enabled = false;
                    MessageBox.Show("调整数值超限");
                }
            }
        }
        private void CH13A11_25P_gamma(Object myObject, EventArgs e)
        {
            int total_points = Diven_Gamma[0].Points_num;
            double L_X, L_Y, L_Z, lumr, lumg, lumb;

            frmHelp.Msr_CASDK();

            if (Gamma_adjust_timeout_flag == true)//如果是0绑点
            {
                flag1 = 0;
                flag2 = 0;
                flag3 = 0;
            }
            else
            {
                if ((frmHelp.CASDK_LUM < (D_lum[index] + D_lum[index] * Diven_Offset[index].LUM_OFF / 100)) && (frmHelp.CASDK_LUM > (D_lum[index] - D_lum[index] * Diven_Offset[index].LUM_OFF / 100)))//G
                { flag1 = 0; }
                else
                { flag1 = 1; }
                if ((frmHelp.CASDK_x < (Diven_Gamma[0].X + Diven_Offset[index].X_OFF)) && (frmHelp.CASDK_x > (Diven_Gamma[0].X - Diven_Offset[index].X_OFF)) && flag1 == 0)//R
                { flag3 = 0; }
                else
                { flag3 = 1; }
                if ((frmHelp.CASDK_y < (Diven_Gamma[0].Y + Diven_Offset[index].Y_OFF)) && (frmHelp.CASDK_y > (Diven_Gamma[0].Y - Diven_Offset[index].Y_OFF)) && flag1 == 0 && flag3 == 0)//B
                { flag2 = 0; }
                else
                { flag2 = 1; }

            }
            if (flag1 == 0 && flag2 == 0 && flag3 == 0)
            {
                T20.Enabled = false;
                //reset-----
                Gamma_adjust_timeout_flag = false;
                frmHelp.Gamma_auto_adjust_count = 0;
                //--------
                /*if (gamma_227 == true && index == 2)
                {
                    index = 1; gamma_227 = false;
                }
                else
                {
                    index++;
                }*/

                if (index == total_points)
                {
                    frmHelp.textBox1.Text = frmHelp.textBox1.Text + "CH13A11 gamma调试完毕!\r\n";
                }
                if (index < total_points)
                {
                    frmHelp.numPatternR.Value = Diven_Offset[index].NO;//固定255灰阶
                    frmHelp.numPatternG.Value = Diven_Offset[index].NO;
                    frmHelp.numPatternB.Value = Diven_Offset[index].NO;

                    Application.DoEvents();
                    frmHelp.OLED_Show_Click(frmHelp.btnPatternW, null);//写入Pattern参数

                    Thread.Sleep(200); //1秒=1000毫秒，
                    T20.Enabled = true;
                    flag1 = 1;
                    flag2 = 1;
                    flag3 = 1;
                }
            }
            else
            {
                decimal r = 0, g = 0, b = 0;
                frmHelp.Gamma_auto_adjust_count_set = 50;

                CaSDKObj.Lvxy_to_XYZ(frmHelp.CASDK_LUM, frmHelp.CASDK_x, frmHelp.CASDK_y, out L_X, out L_Y, out L_Z);
                lumr = L_X;
                lumg = L_Y;
                lumb = L_Z;

                try
                {
                    switch (index)
                    {
                        case 0:
                            {
                                frmHelp.Gamma_auto_adjust_count_set = 75;
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R24.Value, CH13A11_G24.Value, CH13A11_B24.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R24.Value = r;
                                CH13A11_G24.Value = g;
                                CH13A11_B24.Value = b;

                                if (CH13A11_G24.Value <= CH13A11_G23.Value)
                                {
                                    CH13A11_R23.Value = r - 0x10; CH13A11_G23.Value = g - 0x10; CH13A11_B23.Value = b - 0x10;
                                }

                            }
                            break;

                        case 1:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R23.Value, CH13A11_G23.Value, CH13A11_B23.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R23.Value = r;
                                CH13A11_G23.Value = g;
                                CH13A11_B23.Value = b;

                                if (CH13A11_G23.Value <= CH13A11_G22.Value)
                                {
                                    CH13A11_R22.Value = r - 0x10; CH13A11_G22.Value = g - 0x10; CH13A11_B22.Value = b - 0x10;
                                }

                            }
                            break;

                        case 2:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R22.Value, CH13A11_G22.Value, CH13A11_B22.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R22.Value = r;
                                CH13A11_G22.Value = g;
                                CH13A11_B22.Value = b;

                                if (CH13A11_G22.Value <= CH13A11_G21.Value)
                                {
                                    CH13A11_R21.Value = r - 0x10; CH13A11_G21.Value = g - 0x10; CH13A11_B21.Value = b - 0x10;
                                }

                            }
                            break;

                        case 3:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R21.Value, CH13A11_G21.Value, CH13A11_B21.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R21.Value = r;
                                CH13A11_G21.Value = g;
                                CH13A11_B21.Value = b;

                                if (CH13A11_G21.Value <= CH13A11_G20.Value)
                                {
                                    CH13A11_R20.Value = r - 0x10; CH13A11_G20.Value = g - 0x10; CH13A11_B20.Value = b - 0x10;
                                }
                            }
                            break;

                        case 4:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R20.Value, CH13A11_G20.Value, CH13A11_B20.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R20.Value = r;
                                CH13A11_G20.Value = g;
                                CH13A11_B20.Value = b;

                                if (CH13A11_G20.Value <= CH13A11_G19.Value)
                                {
                                    CH13A11_R19.Value = r - 0x10; CH13A11_G19.Value = g - 0x10; CH13A11_B19.Value = b - 0x10;
                                }
                            }
                            break;

                        case 5:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R19.Value, CH13A11_G19.Value, CH13A11_B19.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R19.Value = r;
                                CH13A11_G19.Value = g;
                                CH13A11_B19.Value = b;

                                if (CH13A11_G19.Value <= CH13A11_G18.Value)
                                {
                                    CH13A11_R18.Value = r - 0x10; CH13A11_G18.Value = g - 0x10; CH13A11_B18.Value = b - 0x10;
                                }
                            }
                            break;

                        case 6:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R18.Value, CH13A11_G18.Value, CH13A11_B18.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R18.Value = r;
                                CH13A11_G18.Value = g;
                                CH13A11_B18.Value = b;

                                if (CH13A11_G18.Value <= CH13A11_G17.Value)
                                {
                                    CH13A11_R17.Value = r - 0x10; CH13A11_G17.Value = g - 0x10; CH13A11_B17.Value = b - 0x10;
                                }
                            }
                            break;

                        case 7:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R17.Value, CH13A11_G17.Value, CH13A11_B17.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R17.Value = r;
                                CH13A11_G17.Value = g;
                                CH13A11_B17.Value = b;

                                if (CH13A11_G17.Value <= CH13A11_G16.Value)
                                {
                                    CH13A11_R16.Value = r - 0x10; CH13A11_G16.Value = g - 0x10; CH13A11_B16.Value = b - 0x10;
                                }
                            }
                            break;

                        case 8:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R16.Value, CH13A11_G16.Value, CH13A11_B16.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R16.Value = r;
                                CH13A11_G16.Value = g;
                                CH13A11_B16.Value = b;

                                if (CH13A11_G16.Value <= CH13A11_G15.Value)
                                {
                                    CH13A11_R15.Value = r - 0x10; CH13A11_G15.Value = g - 0x10; CH13A11_B15.Value = b - 0x10;
                                }
                            }
                            break;

                        case 9:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R15.Value, CH13A11_G15.Value, CH13A11_B15.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R15.Value = r;
                                CH13A11_G15.Value = g;
                                CH13A11_B15.Value = b;

                                if (CH13A11_G15.Value <= CH13A11_G14.Value)
                                {
                                    CH13A11_R14.Value = r - 0x10; CH13A11_G14.Value = g - 0x10; CH13A11_B14.Value = b - 0x10;
                                }
                            }
                            break;
                        case 10:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R14.Value, CH13A11_G14.Value, CH13A11_B14.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R14.Value = r;
                                CH13A11_G14.Value = g;
                                CH13A11_B14.Value = b;

                                if (CH13A11_G14.Value <= CH13A11_G13.Value)
                                {
                                    CH13A11_R13.Value = r - 0x10; CH13A11_G13.Value = g - 0x10; CH13A11_B13.Value = b - 0x10;
                                }
                            }
                            break;
                        case 11:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R13.Value, CH13A11_G13.Value, CH13A11_B13.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R13.Value = r;
                                CH13A11_G13.Value = g;
                                CH13A11_B13.Value = b;

                                if (CH13A11_G13.Value <= CH13A11_G12.Value)
                                {
                                    CH13A11_R12.Value = r - 0x10; CH13A11_G12.Value = g - 0x10; CH13A11_B12.Value = b - 0x10;
                                }
                            }
                            break;
                        case 12:
                            {
                                frmHelp.Gamma_auto_adjust_count_set = 30;
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R12.Value, CH13A11_G12.Value, CH13A11_B12.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R12.Value = r;
                                CH13A11_G12.Value = g;
                                CH13A11_B12.Value = b;
                                if (CH13A11_G12.Value <= CH13A11_G11.Value)
                                {
                                    CH13A11_R11.Value = r - 0x10; CH13A11_G11.Value = g - 0x10; CH13A11_B11.Value = b - 0x10;
                                }
                            }
                            break;
                        case 13:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R11.Value, CH13A11_G11.Value, CH13A11_B11.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R11.Value = r;
                                CH13A11_G11.Value = g;
                                CH13A11_B11.Value = b;

                                if (CH13A11_G11.Value <= CH13A11_G10.Value)
                                {
                                    CH13A11_R10.Value = r - 0x10; CH13A11_G10.Value = g - 0x10; CH13A11_B10.Value = b - 0x10;
                                }
                            }
                            break;
                        case 14:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R10.Value, CH13A11_G10.Value, CH13A11_B10.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R10.Value = r;
                                CH13A11_G10.Value = g;
                                CH13A11_B10.Value = b;

                                if (CH13A11_G10.Value <= CH13A11_G9.Value)
                                {
                                    CH13A11_R9.Value = r - 0x05; CH13A11_G9.Value = g - 0x05; CH13A11_B9.Value = b - 0x05;
                                }
                            }
                            break;
                        case 15:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R9.Value, CH13A11_G9.Value, CH13A11_B9.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R9.Value = r;
                                CH13A11_G9.Value = g;
                                CH13A11_B9.Value = b;

                                if (CH13A11_G9.Value <= CH13A11_G8.Value)
                                {
                                    CH13A11_R8.Value = r - 0x05; CH13A11_G8.Value = g - 0x05; CH13A11_B8.Value = b - 0x05;
                                }
                            }
                            break;
                        case 16:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R8.Value, CH13A11_G8.Value, CH13A11_B8.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R8.Value = r;
                                CH13A11_G8.Value = g;
                                CH13A11_B8.Value = b;

                                if (CH13A11_G8.Value <= CH13A11_G7.Value)
                                {
                                    CH13A11_R7.Value = r - 0x05; CH13A11_G7.Value = g - 0x05; CH13A11_B7.Value = b - 0x05;
                                }
                            }
                            break;
                        case 17:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R7.Value, CH13A11_G7.Value, CH13A11_B7.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R7.Value = r;
                                CH13A11_G7.Value = g;
                                CH13A11_B7.Value = b;

                                if (CH13A11_G7.Value <= CH13A11_G6.Value)
                                {
                                    CH13A11_R6.Value = r - 0x03; CH13A11_G6.Value = g - 0x03; CH13A11_B6.Value = b - 0x03;
                                }
                            }
                            break;
                        case 18:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R6.Value, CH13A11_G6.Value, CH13A11_B6.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R6.Value = r;
                                CH13A11_G6.Value = g;
                                CH13A11_B6.Value = b;

                                if (CH13A11_G6.Value <= CH13A11_G5.Value)
                                {
                                    CH13A11_R5.Value = r - 0x03; CH13A11_G5.Value = g - 0x03; CH13A11_B5.Value = b - 0x03;
                                }
                            }
                            break;
                        case 19:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R5.Value, CH13A11_G5.Value, CH13A11_B5.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R5.Value = r;
                                CH13A11_G5.Value = g;
                                CH13A11_B5.Value = b;

                                if (CH13A11_G5.Value <= CH13A11_G4.Value)
                                {
                                    CH13A11_R4.Value = r - 0x03; CH13A11_G4.Value = g - 0x03; CH13A11_B4.Value = b - 0x03;
                                }
                            }
                            break;
                        case 20:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R4.Value, CH13A11_G4.Value, CH13A11_B4.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R4.Value = r;
                                CH13A11_G4.Value = g;
                                CH13A11_B4.Value = b;

                                if (CH13A11_G4.Value <= CH13A11_G3.Value)
                                {
                                    CH13A11_R3.Value = r - 0x01; CH13A11_G3.Value = g - 0x01; CH13A11_B3.Value = b - 0x01;
                                }
                            }
                            break;
                        case 21:
                            {
                                frmHelp.Gamma_auto_adjust_count_set = 20;
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R3.Value, CH13A11_G3.Value, CH13A11_B3.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R3.Value = r;
                                CH13A11_G3.Value = g;
                                CH13A11_B3.Value = b;

                                if (CH13A11_G3.Value <= CH13A11_G2.Value)
                                {
                                    CH13A11_R2.Value = r - 01; CH13A11_G2.Value = g - 0x01; CH13A11_B2.Value = b - 0x01;
                                }
                            }
                            break;
                        case 22:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R2.Value, CH13A11_G2.Value, CH13A11_B2.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R2.Value = r;
                                CH13A11_G2.Value = g;
                                CH13A11_B2.Value = b;

                                if (CH13A11_G2.Value <= CH13A11_G1.Value)
                                {
                                    CH13A11_R1.Value = r - 0x10; CH13A11_G1.Value = g - 0x10; CH13A11_B1.Value = b - 0x10;
                                }
                            }
                            break;
                        case 23:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R1.Value, CH13A11_G1.Value, CH13A11_B1.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R1.Value = r;
                                CH13A11_G1.Value = g;
                                CH13A11_B1.Value = b;

                                if (CH13A11_G1.Value <= CH13A11_G0.Value)
                                {
                                    CH13A11_R0.Value = r - 0x10; CH13A11_G0.Value = g - 0x10; CH13A11_B0.Value = b - 0x10;
                                }
                            }
                            break;
                        case 24:
                            {
                                //frmHelp.R6645x_Gamma_auto_Adujst(flag1, flag3, flag2, 20, 2, 1, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], flexible_gamma_count, NT37700C_R7.Value, NT37700C_G7.Value, NT37700C_B7.Value, Diven_Offset[index].NO, Diven_Offset[index].NO, Diven_Offset[index].NO, 0x3ff, 0x3ff, 0x3ff, 0x3ff, 0x3ff, 0x3ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                Gamma_adjust_timeout_flag = true;
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R0.Value = 0;
                                CH13A11_G0.Value = 0;
                                CH13A11_B0.Value = 0;

                            }
                            break;
                        default:
                            break;
                    }
                    if (index != 24)
                    {
                        //frmHelp.auto_gamma_write(gamma_r[total_points - 1 - index], Convert.ToUInt16(r), gamma_g[total_points - 1 - index], Convert.ToUInt16(g), gamma_b[total_points - 1 - index], Convert.ToUInt16(b));
                        CH13A11_GammaW_RED_Click(CH13A11_GammaW_RED, null);
                        Thread.Sleep(15);
                        CH13A11_GammaW_RED_Click(CH13A11_GammaW_GREEN, null);
                        Thread.Sleep(15);
                        CH13A11_GammaW_RED_Click(CH13A11_GammaW_BLUE, null);
                        Thread.Sleep(15);
                    }
                    else
                    {
                        CH13A11_GammaW_RED_Click(CH13A11_GammaW_RED, e);
                        Thread.Sleep(15);
                        CH13A11_GammaW_RED_Click(CH13A11_GammaW_GREEN, e);
                        Thread.Sleep(15);
                        CH13A11_GammaW_RED_Click(CH13A11_GammaW_BLUE, e);
                        Thread.Sleep(15);
                        //frmHelp.auto_gamma_write(gamma_r[total_points - 1 - index], 0, gamma_g[total_points - 1 - index], 0, gamma_b[total_points - 1 - index], 0);

                    }
                }
                catch
                {
                    T20.Enabled = false;
                    MessageBox.Show("调整数值超限");
                }
            }
        }

        private void CH13A11_34P_gamma(Object myObject, EventArgs e)
        {
            int total_points = Diven_Gamma[0].Points_num;
            //int total_points = 34;
            double L_X, L_Y, L_Z, lumr, lumg, lumb;

            frmHelp.Msr_CASDK();

            if (Gamma_adjust_timeout_flag == true)//如果是0绑点
            {
                flag1 = 0;
                flag2 = 0;
                flag3 = 0;
            }
            else
            {
                if ((frmHelp.CASDK_LUM < (D_lum[index] + D_lum[index] * Diven_Offset[index].LUM_OFF / 100)) && (frmHelp.CASDK_LUM > (D_lum[index] - D_lum[index] * Diven_Offset[index].LUM_OFF / 100)))//G
                { flag1 = 0; }
                else
                { flag1 = 1; }
                if ((frmHelp.CASDK_x < (Diven_Gamma[0].X + Diven_Offset[index].X_OFF)) && (frmHelp.CASDK_x > (Diven_Gamma[0].X - Diven_Offset[index].X_OFF)) && flag1 == 0)//R
                { flag3 = 0; }
                else
                { flag3 = 1; }
                if ((frmHelp.CASDK_y < (Diven_Gamma[0].Y + Diven_Offset[index].Y_OFF)) && (frmHelp.CASDK_y > (Diven_Gamma[0].Y - Diven_Offset[index].Y_OFF)) && flag1 == 0 && flag3 == 0)//B
                { flag2 = 0; }
                else
                { flag2 = 1; }

            }
            if (flag1 == 0 && flag2 == 0 && flag3 == 0)
            {
                T20.Enabled = false;
                //reset-----
                Gamma_adjust_timeout_flag = false;
                frmHelp.Gamma_auto_adjust_count = 0;
                //--------
                index++;

                if (index == total_points)
                {
                    frmHelp.textBox1.Text = frmHelp.textBox1.Text + "CH13A11 gamma调试完毕!\r\n";
                }
                if (index < total_points)
                {
                    frmHelp.numPatternR.Value = Diven_Offset[index].NO;//固定255灰阶
                    frmHelp.numPatternG.Value = Diven_Offset[index].NO;
                    frmHelp.numPatternB.Value = Diven_Offset[index].NO;

                    Application.DoEvents();
                    frmHelp.OLED_Show_Click(frmHelp.btnPatternW, null);//写入Pattern参数

                    Thread.Sleep(200); //1秒=1000毫秒，
                    T20.Enabled = true;
                    flag1 = 1;
                    flag2 = 1;
                    flag3 = 1;
                }
            }
            else
            {
                decimal r = 0, g = 0, b = 0;
                frmHelp.Gamma_auto_adjust_count_set = 50;

                CaSDKObj.Lvxy_to_XYZ(frmHelp.CASDK_LUM, frmHelp.CASDK_x, frmHelp.CASDK_y, out L_X, out L_Y, out L_Z);
                lumr = L_X;
                lumg = L_Y;
                lumb = L_Z;

                try
                {
                    switch (index)
                    {
                        case 0:
                            {
                                frmHelp.Gamma_auto_adjust_count_set = 75;
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R33.Value, CH13A11_G33.Value, CH13A11_B33.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R33.Value = r;
                                CH13A11_G33.Value = g;
                                CH13A11_B33.Value = b;

                                if (CH13A11_G33.Value <= CH13A11_G32.Value)
                                {
                                    CH13A11_R32.Value = r - 0x10; CH13A11_G32.Value = g - 0x10; CH13A11_B32.Value = b - 0x10;
                                }

                            }
                            break;
                        case 1:
                            {
                                frmHelp.Gamma_auto_adjust_count_set = 75;
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R32.Value, CH13A11_G32.Value, CH13A11_B32.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R32.Value = r;
                                CH13A11_G32.Value = g;
                                CH13A11_B32.Value = b;

                                if (CH13A11_G32.Value <= CH13A11_G31.Value)
                                {
                                    CH13A11_R31.Value = r - 0x10; CH13A11_G31.Value = g - 0x10; CH13A11_B31.Value = b - 0x10;
                                }

                            }
                            break;
                        case 2:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R31.Value, CH13A11_G31.Value, CH13A11_B31.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R31.Value = r;
                                CH13A11_G31.Value = g;
                                CH13A11_B31.Value = b;

                                if (CH13A11_G31.Value <= CH13A11_G30.Value)
                                {
                                    CH13A11_R30.Value = r - 0x10; CH13A11_G30.Value = g - 0x10; CH13A11_B30.Value = b - 0x10;
                                }

                            }
                            break;
                        case 3:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R30.Value, CH13A11_G30.Value, CH13A11_B30.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R30.Value = r;
                                CH13A11_G30.Value = g;
                                CH13A11_B30.Value = b;

                                if (CH13A11_G30.Value <= CH13A11_G29.Value)
                                {
                                    CH13A11_R29.Value = r - 0x10; CH13A11_G29.Value = g - 0x10; CH13A11_B29.Value = b - 0x10;
                                }

                            }
                            break;

                        case 4:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R29.Value, CH13A11_G29.Value, CH13A11_B29.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R29.Value = r;
                                CH13A11_G29.Value = g;
                                CH13A11_B29.Value = b;

                                if (CH13A11_G29.Value <= CH13A11_G28.Value)
                                {
                                    CH13A11_R28.Value = r - 0x10; CH13A11_G28.Value = g - 0x10; CH13A11_B28.Value = b - 0x10;
                                }

                            }
                            break;
                        case 5:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R28.Value, CH13A11_G28.Value, CH13A11_B28.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R28.Value = r;
                                CH13A11_G28.Value = g;
                                CH13A11_B28.Value = b;

                                if (CH13A11_G28.Value <= CH13A11_G27.Value)
                                {
                                    CH13A11_R27.Value = r - 0x10; CH13A11_G27.Value = g - 0x10; CH13A11_B27.Value = b - 0x10;
                                }

                            }
                            break;
                        case 6:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R27.Value, CH13A11_G27.Value, CH13A11_B27.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R27.Value = r;
                                CH13A11_G27.Value = g;
                                CH13A11_B27.Value = b;

                                if (CH13A11_G27.Value <= CH13A11_G26.Value)
                                {
                                    CH13A11_R26.Value = r - 0x10; CH13A11_G26.Value = g - 0x10; CH13A11_B26.Value = b - 0x10;
                                }

                            }
                            break;
                        case 7:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R26.Value, CH13A11_G26.Value, CH13A11_B26.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R26.Value = r;
                                CH13A11_G26.Value = g;
                                CH13A11_B26.Value = b;

                                if (CH13A11_G26.Value <= CH13A11_G25.Value)
                                {
                                    CH13A11_R25.Value = r - 0x10; CH13A11_G25.Value = g - 0x10; CH13A11_B25.Value = b - 0x10;
                                }

                            }
                            break;
                        case 8:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R25.Value, CH13A11_G25.Value, CH13A11_B25.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R25.Value = r;
                                CH13A11_G25.Value = g;
                                CH13A11_B25.Value = b;

                                if (CH13A11_G25.Value <= CH13A11_G24.Value)
                                {
                                    CH13A11_R24.Value = r - 0x10; CH13A11_G24.Value = g - 0x10; CH13A11_B24.Value = b - 0x10;
                                }

                            }
                            break;

                        case 9:
                            {
                                frmHelp.Gamma_auto_adjust_count_set = 75;
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R24.Value, CH13A11_G24.Value, CH13A11_B24.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R24.Value = r;
                                CH13A11_G24.Value = g;
                                CH13A11_B24.Value = b;

                                if (CH13A11_G24.Value <= CH13A11_G23.Value)
                                {
                                    CH13A11_R23.Value = r - 0x10; CH13A11_G23.Value = g - 0x10; CH13A11_B23.Value = b - 0x10;
                                }

                            }
                            break;

                        case 10:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R23.Value, CH13A11_G23.Value, CH13A11_B23.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R23.Value = r;
                                CH13A11_G23.Value = g;
                                CH13A11_B23.Value = b;

                                if (CH13A11_G23.Value <= CH13A11_G22.Value)
                                {
                                    CH13A11_R22.Value = r - 0x10; CH13A11_G22.Value = g - 0x10; CH13A11_B22.Value = b - 0x10;
                                }

                            }
                            break;

                        case 11:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R22.Value, CH13A11_G22.Value, CH13A11_B22.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R22.Value = r;
                                CH13A11_G22.Value = g;
                                CH13A11_B22.Value = b;

                                if (CH13A11_G22.Value <= CH13A11_G21.Value)
                                {
                                    CH13A11_R21.Value = r - 0x10; CH13A11_G21.Value = g - 0x10; CH13A11_B21.Value = b - 0x10;
                                }

                            }
                            break;

                        case 12:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R21.Value, CH13A11_G21.Value, CH13A11_B21.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R21.Value = r;
                                CH13A11_G21.Value = g;
                                CH13A11_B21.Value = b;

                                if (CH13A11_G21.Value <= CH13A11_G20.Value)
                                {
                                    CH13A11_R20.Value = r - 0x10; CH13A11_G20.Value = g - 0x10; CH13A11_B20.Value = b - 0x10;
                                }
                            }
                            break;

                        case 13:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R20.Value, CH13A11_G20.Value, CH13A11_B20.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R20.Value = r;
                                CH13A11_G20.Value = g;
                                CH13A11_B20.Value = b;

                                if (CH13A11_G20.Value <= CH13A11_G19.Value)
                                {
                                    CH13A11_R19.Value = r - 0x10; CH13A11_G19.Value = g - 0x10; CH13A11_B19.Value = b - 0x10;
                                }
                            }
                            break;

                        case 14:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R19.Value, CH13A11_G19.Value, CH13A11_B19.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R19.Value = r;
                                CH13A11_G19.Value = g;
                                CH13A11_B19.Value = b;

                                if (CH13A11_G19.Value <= CH13A11_G18.Value)
                                {
                                    CH13A11_R18.Value = r - 0x10; CH13A11_G18.Value = g - 0x10; CH13A11_B18.Value = b - 0x10;
                                }
                            }
                            break;

                        case 15:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R18.Value, CH13A11_G18.Value, CH13A11_B18.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R18.Value = r;
                                CH13A11_G18.Value = g;
                                CH13A11_B18.Value = b;

                                if (CH13A11_G18.Value <= CH13A11_G17.Value)
                                {
                                    CH13A11_R17.Value = r - 0x10; CH13A11_G17.Value = g - 0x10; CH13A11_B17.Value = b - 0x10;
                                }
                            }
                            break;

                        case 16:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R17.Value, CH13A11_G17.Value, CH13A11_B17.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R17.Value = r;
                                CH13A11_G17.Value = g;
                                CH13A11_B17.Value = b;

                                if (CH13A11_G17.Value <= CH13A11_G16.Value)
                                {
                                    CH13A11_R16.Value = r - 0x10; CH13A11_G16.Value = g - 0x10; CH13A11_B16.Value = b - 0x10;
                                }
                            }
                            break;

                        case 17:
                            {
                                frmHelp.Gamma_auto_adjust_count_set = 100;
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R16.Value, CH13A11_G16.Value, CH13A11_B16.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R16.Value = r;
                                CH13A11_G16.Value = g;
                                CH13A11_B16.Value = b;

                                if (CH13A11_G16.Value <= CH13A11_G15.Value)
                                {
                                    CH13A11_R15.Value = r - 0x10; CH13A11_G15.Value = g - 0x10; CH13A11_B15.Value = b - 0x10;
                                }
                            }
                            break;

                        case 18:
                            {
                                frmHelp.Gamma_auto_adjust_count_set = 100;
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R15.Value, CH13A11_G15.Value, CH13A11_B15.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R15.Value = r;
                                CH13A11_G15.Value = g;
                                CH13A11_B15.Value = b;

                                if (CH13A11_G15.Value <= CH13A11_G14.Value)
                                {
                                    CH13A11_R14.Value = r - 0x01; CH13A11_G14.Value = g - 0x01; CH13A11_B14.Value = b - 0x01;
                                }
                            }
                            break;
                        case 19:
                            {
                                frmHelp.Gamma_auto_adjust_count_set = 100;
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R14.Value, CH13A11_G14.Value, CH13A11_B14.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R14.Value = r;
                                CH13A11_G14.Value = g;
                                CH13A11_B14.Value = b;

                                if (CH13A11_G14.Value <= CH13A11_G13.Value)
                                {
                                    CH13A11_R13.Value = r - 0x01; CH13A11_G13.Value = g - 0x01; CH13A11_B13.Value = b - 0x01;
                                }
                            }
                            break;
                        case 20:
                            {
                                frmHelp.Gamma_auto_adjust_count_set = 75;
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R13.Value, CH13A11_G13.Value, CH13A11_B13.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R13.Value = r;
                                CH13A11_G13.Value = g;
                                CH13A11_B13.Value = b;

                                if (CH13A11_G13.Value <= CH13A11_G12.Value)
                                {
                                    CH13A11_R12.Value = r - 0x10; CH13A11_G12.Value = g - 0x10; CH13A11_B12.Value = b - 0x10;
                                }
                            }
                            break;
                        case 21:
                            {
                                frmHelp.Gamma_auto_adjust_count_set = 30;
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R12.Value, CH13A11_G12.Value, CH13A11_B12.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R12.Value = r;
                                CH13A11_G12.Value = g;
                                CH13A11_B12.Value = b;
                                if (CH13A11_G12.Value <= CH13A11_G11.Value)
                                {
                                    CH13A11_R11.Value = r - 0x10; CH13A11_G11.Value = g - 0x10; CH13A11_B11.Value = b - 0x10;
                                }
                            }
                            break;
                        case 22:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R11.Value, CH13A11_G11.Value, CH13A11_B11.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R11.Value = r;
                                CH13A11_G11.Value = g;
                                CH13A11_B11.Value = b;

                                if (CH13A11_G11.Value <= CH13A11_G10.Value)
                                {
                                    CH13A11_R10.Value = r - 0x10; CH13A11_G10.Value = g - 0x10; CH13A11_B10.Value = b - 0x10;
                                }
                            }
                            break;
                        case 23:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R10.Value, CH13A11_G10.Value, CH13A11_B10.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R10.Value = r;
                                CH13A11_G10.Value = g;
                                CH13A11_B10.Value = b;

                                if (CH13A11_G10.Value <= CH13A11_G9.Value)
                                {
                                    CH13A11_R9.Value = r - 0x05; CH13A11_G9.Value = g - 0x05; CH13A11_B9.Value = b - 0x05;
                                }
                            }
                            break;
                        case 24:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R9.Value, CH13A11_G9.Value, CH13A11_B9.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R9.Value = r;
                                CH13A11_G9.Value = g;
                                CH13A11_B9.Value = b;

                                if (CH13A11_G9.Value <= CH13A11_G8.Value)
                                {
                                    CH13A11_R8.Value = r - 0x05; CH13A11_G8.Value = g - 0x05; CH13A11_B8.Value = b - 0x05;
                                }
                            }
                            break;
                        case 25:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R8.Value, CH13A11_G8.Value, CH13A11_B8.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R8.Value = r;
                                CH13A11_G8.Value = g;
                                CH13A11_B8.Value = b;

                                if (CH13A11_G8.Value <= CH13A11_G7.Value)
                                {
                                    CH13A11_R7.Value = r - 0x05; CH13A11_G7.Value = g - 0x05; CH13A11_B7.Value = b - 0x05;
                                }
                            }
                            break;
                        case 26:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R7.Value, CH13A11_G7.Value, CH13A11_B7.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R7.Value = r;
                                CH13A11_G7.Value = g;
                                CH13A11_B7.Value = b;

                                if (CH13A11_G7.Value <= CH13A11_G6.Value)
                                {
                                    CH13A11_R6.Value = r - 0x03; CH13A11_G6.Value = g - 0x03; CH13A11_B6.Value = b - 0x03;
                                }
                            }
                            break;
                        case 27:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R6.Value, CH13A11_G6.Value, CH13A11_B6.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R6.Value = r;
                                CH13A11_G6.Value = g;
                                CH13A11_B6.Value = b;

                                if (CH13A11_G6.Value <= CH13A11_G5.Value)
                                {
                                    CH13A11_R5.Value = r - 0x03; CH13A11_G5.Value = g - 0x03; CH13A11_B5.Value = b - 0x03;
                                }
                            }
                            break;
                        case 28:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R5.Value, CH13A11_G5.Value, CH13A11_B5.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R5.Value = r;
                                CH13A11_G5.Value = g;
                                CH13A11_B5.Value = b;

                                if (CH13A11_G5.Value <= CH13A11_G4.Value)
                                {
                                    CH13A11_R4.Value = r - 0x03; CH13A11_G4.Value = g - 0x03; CH13A11_B4.Value = b - 0x03;
                                }
                            }
                            break;
                        case 29:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R4.Value, CH13A11_G4.Value, CH13A11_B4.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R4.Value = r;
                                CH13A11_G4.Value = g;
                                CH13A11_B4.Value = b;

                                if (CH13A11_G4.Value <= CH13A11_G3.Value)
                                {
                                    CH13A11_R3.Value = r - 0x01; CH13A11_G3.Value = g - 0x01; CH13A11_B3.Value = b - 0x01;
                                }
                            }
                            break;
                        case 30:
                            {
                                frmHelp.Gamma_auto_adjust_count_set = 20;
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R3.Value, CH13A11_G3.Value, CH13A11_B3.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R3.Value = r;
                                CH13A11_G3.Value = g;
                                CH13A11_B3.Value = b;

                                if (CH13A11_G3.Value <= CH13A11_G2.Value)
                                {
                                    CH13A11_R2.Value = r - 0x01; CH13A11_G2.Value = g - 0x01; CH13A11_B2.Value = b - 0x01;
                                }
                            }
                            break;
                        case 31:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R2.Value, CH13A11_G2.Value, CH13A11_B2.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R2.Value = r;
                                CH13A11_G2.Value = g;
                                CH13A11_B2.Value = b;

                                if (CH13A11_G2.Value <= CH13A11_G1.Value)
                                {
                                    CH13A11_R1.Value = r - 0x01; CH13A11_G1.Value = g - 0x01; CH13A11_B1.Value = b - 0x01;
                                }
                            }
                            break;
                        case 32:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], CH13A11_R1.Value, CH13A11_G1.Value, CH13A11_B1.Value, Diven_Offset[index].NO, 0x7ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R1.Value = r;
                                CH13A11_G1.Value = g;
                                CH13A11_B1.Value = b;

                                if (CH13A11_G1.Value <= CH13A11_G0.Value)
                                {
                                    CH13A11_R0.Value = r - 0x01; CH13A11_G0.Value = g - 0x01; CH13A11_B0.Value = b - 0x01;
                                }
                            }
                            break;
                        case 33:
                            {
                                //frmHelp.R6645x_Gamma_auto_Adujst(flag1, flag3, flag2, 20, 2, 1, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], flexible_gamma_count, NT37700C_R7.Value, NT37700C_G7.Value, NT37700C_B7.Value, Diven_Offset[index].NO, Diven_Offset[index].NO, Diven_Offset[index].NO, 0x3ff, 0x3ff, 0x3ff, 0x3ff, 0x3ff, 0x3ff, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                Gamma_adjust_timeout_flag = true;
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                CH13A11_R0.Value = 0;
                                CH13A11_G0.Value = 0;
                                CH13A11_B0.Value = 0;

                            }
                            break;
                        default:
                            break;
                    }
                    if (index != 33)
                    {
                        //frmHelp.auto_gamma_write(gamma_r[total_points - 1 - index], Convert.ToUInt16(r), gamma_g[total_points - 1 - index], Convert.ToUInt16(g), gamma_b[total_points - 1 - index], Convert.ToUInt16(b));
                        CH13A11_GammaW_RED_Click(CH13A11_GammaW_RED, null);
                        Thread.Sleep(15);
                        CH13A11_GammaW_RED_Click(CH13A11_GammaW_GREEN, null);
                        Thread.Sleep(15);
                        CH13A11_GammaW_RED_Click(CH13A11_GammaW_BLUE, null);
                        Thread.Sleep(15);
                    }
                    else
                    {
                        CH13A11_GammaW_RED_Click(CH13A11_GammaW_RED, e);
                        Thread.Sleep(15);
                        CH13A11_GammaW_RED_Click(CH13A11_GammaW_GREEN, e);
                        Thread.Sleep(15);
                        CH13A11_GammaW_RED_Click(CH13A11_GammaW_BLUE, e);
                        Thread.Sleep(15);
                        //frmHelp.auto_gamma_write(gamma_r[total_points - 1 - index], 0, gamma_g[total_points - 1 - index], 0, gamma_b[total_points - 1 - index], 0);

                    }
                }
                catch
                {
                    T20.Enabled = false;
                    MessageBox.Show("调整数值超限");
                }
            }
        }

        private void CH13A11_GammaW_RED_Click(object sender, EventArgs e)
        {
            Button btnTmp = (Button)sender;
            Send_buf = new byte[58];
            Setting.TempRecord.cmdLen = 58;
            Send_buf[2] = 53;
            Send_buf[0] = 0x81; //CH13A11

            //----------------------------------------------------------------------------------
            switch (btnTmp.Name)
            {
                case "CH13A11_GammaW_RED":
                    {
                        Send_buf[1] = 0x08;
                        Send_buf[3] = 0x01; //RED

                        if (rbt_CH13A11_25points.Checked == true)
                        {
                            Send_buf[4] = Convert.ToByte(Convert.ToUInt16(CH13A11_R0.Value.ToString()) >> 8);//高位，8--10
                            Send_buf[5] = Convert.ToByte((Convert.ToUInt16(CH13A11_R0.Value.ToString())) & 0xff);//低位，0--7
                            Send_buf[6] = Convert.ToByte(Convert.ToUInt16(CH13A11_R1.Value.ToString()) >> 8);
                            Send_buf[7] = Convert.ToByte((Convert.ToUInt16(CH13A11_R1.Value.ToString())) & 0xff);
                            Send_buf[8] = Convert.ToByte(Convert.ToUInt16(CH13A11_R2.Value.ToString()) >> 8);
                            Send_buf[9] = Convert.ToByte((Convert.ToUInt16(CH13A11_R2.Value.ToString())) & 0xff);
                            Send_buf[10] = Convert.ToByte(Convert.ToUInt16(CH13A11_R3.Value.ToString()) >> 8);
                            Send_buf[11] = Convert.ToByte((Convert.ToUInt16(CH13A11_R3.Value.ToString())) & 0xff);
                            Send_buf[12] = Convert.ToByte(Convert.ToUInt16(CH13A11_R4.Value.ToString()) >> 8);
                            Send_buf[13] = Convert.ToByte((Convert.ToUInt16(CH13A11_R4.Value.ToString())) & 0xff);
                            Send_buf[14] = Convert.ToByte(Convert.ToUInt16(CH13A11_R5.Value.ToString()) >> 8);
                            Send_buf[15] = Convert.ToByte((Convert.ToUInt16(CH13A11_R5.Value.ToString())) & 0xff);
                            Send_buf[16] = Convert.ToByte(Convert.ToUInt16(CH13A11_R6.Value.ToString()) >> 8);
                            Send_buf[17] = Convert.ToByte((Convert.ToUInt16(CH13A11_R6.Value.ToString())) & 0xff);
                            Send_buf[18] = Convert.ToByte(Convert.ToUInt16(CH13A11_R7.Value.ToString()) >> 8);
                            Send_buf[19] = Convert.ToByte((Convert.ToUInt16(CH13A11_R7.Value.ToString())) & 0xff);
                            Send_buf[20] = Convert.ToByte(Convert.ToUInt16(CH13A11_R8.Value.ToString()) >> 8);
                            Send_buf[21] = Convert.ToByte((Convert.ToUInt16(CH13A11_R8.Value.ToString())) & 0xff);
                            Send_buf[22] = Convert.ToByte(Convert.ToUInt16(CH13A11_R9.Value.ToString()) >> 8);
                            Send_buf[23] = Convert.ToByte((Convert.ToUInt16(CH13A11_R9.Value.ToString())) & 0xff);
                            Send_buf[24] = Convert.ToByte(Convert.ToUInt16(CH13A11_R10.Value.ToString()) >> 8);
                            Send_buf[25] = Convert.ToByte((Convert.ToUInt16(CH13A11_R10.Value.ToString())) & 0xff);
                            Send_buf[26] = Convert.ToByte(Convert.ToUInt16(CH13A11_R11.Value.ToString()) >> 8);
                            Send_buf[27] = Convert.ToByte((Convert.ToUInt16(CH13A11_R11.Value.ToString())) & 0xff);
                            Send_buf[28] = Convert.ToByte(Convert.ToUInt16(CH13A11_R12.Value.ToString()) >> 8);
                            Send_buf[29] = Convert.ToByte((Convert.ToUInt16(CH13A11_R12.Value.ToString())) & 0xff);
                            Send_buf[30] = Convert.ToByte(Convert.ToUInt16(CH13A11_R13.Value.ToString()) >> 8);
                            Send_buf[31] = Convert.ToByte((Convert.ToUInt16(CH13A11_R13.Value.ToString())) & 0xff);
                            Send_buf[32] = Convert.ToByte(Convert.ToUInt16(CH13A11_R14.Value.ToString()) >> 8);
                            Send_buf[33] = Convert.ToByte((Convert.ToUInt16(CH13A11_R14.Value.ToString())) & 0xff);
                            Send_buf[34] = Convert.ToByte(Convert.ToUInt16(CH13A11_R15.Value.ToString()) >> 8);
                            Send_buf[35] = Convert.ToByte((Convert.ToUInt16(CH13A11_R15.Value.ToString())) & 0xff);
                            Send_buf[36] = Convert.ToByte(Convert.ToUInt16(CH13A11_R16.Value.ToString()) >> 8);
                            Send_buf[37] = Convert.ToByte((Convert.ToUInt16(CH13A11_R16.Value.ToString())) & 0xff);
                            Send_buf[38] = Convert.ToByte(Convert.ToUInt16(CH13A11_R17.Value.ToString()) >> 8);
                            Send_buf[39] = Convert.ToByte((Convert.ToUInt16(CH13A11_R17.Value.ToString())) & 0xff);
                            Send_buf[40] = Convert.ToByte(Convert.ToUInt16(CH13A11_R18.Value.ToString()) >> 8);
                            Send_buf[41] = Convert.ToByte((Convert.ToUInt16(CH13A11_R18.Value.ToString())) & 0xff);
                            Send_buf[42] = Convert.ToByte(Convert.ToUInt16(CH13A11_R19.Value.ToString()) >> 8);
                            Send_buf[43] = Convert.ToByte((Convert.ToUInt16(CH13A11_R19.Value.ToString())) & 0xff);
                            Send_buf[44] = Convert.ToByte(Convert.ToUInt16(CH13A11_R20.Value.ToString()) >> 8);
                            Send_buf[45] = Convert.ToByte((Convert.ToUInt16(CH13A11_R20.Value.ToString())) & 0xff);
                            Send_buf[46] = Convert.ToByte(Convert.ToUInt16(CH13A11_R21.Value.ToString()) >> 8);
                            Send_buf[47] = Convert.ToByte((Convert.ToUInt16(CH13A11_R21.Value.ToString())) & 0xff);
                            Send_buf[48] = Convert.ToByte(Convert.ToUInt16(CH13A11_R22.Value.ToString()) >> 8);
                            Send_buf[49] = Convert.ToByte((Convert.ToUInt16(CH13A11_R22.Value.ToString())) & 0xff);
                            Send_buf[50] = Convert.ToByte(Convert.ToUInt16(CH13A11_R23.Value.ToString()) >> 8);
                            Send_buf[51] = Convert.ToByte((Convert.ToUInt16(CH13A11_R23.Value.ToString())) & 0xff);
                            Send_buf[52] = Convert.ToByte(Convert.ToUInt16(CH13A11_R24.Value.ToString()) >> 8);
                            Send_buf[53] = Convert.ToByte((Convert.ToUInt16(CH13A11_R24.Value.ToString())) & 0xff);
                        }

                        else if (rbt_CH13A11_17points.Checked == true)
                        {
                            Send_buf[20] = Convert.ToByte(Convert.ToUInt16(CH13A11_R0.Value.ToString()) >> 8);//高位，8--10
                            Send_buf[21] = Convert.ToByte((Convert.ToUInt16(CH13A11_R0.Value.ToString())) & 0xff);//低位，0--7
                            Send_buf[22] = Convert.ToByte(Convert.ToUInt16(CH13A11_R1.Value.ToString()) >> 8);
                            Send_buf[23] = Convert.ToByte((Convert.ToUInt16(CH13A11_R1.Value.ToString())) & 0xff);
                            Send_buf[24] = Convert.ToByte(Convert.ToUInt16(CH13A11_R2.Value.ToString()) >> 8);
                            Send_buf[25] = Convert.ToByte((Convert.ToUInt16(CH13A11_R2.Value.ToString())) & 0xff);
                            Send_buf[26] = Convert.ToByte(Convert.ToUInt16(CH13A11_R3.Value.ToString()) >> 8);
                            Send_buf[27] = Convert.ToByte((Convert.ToUInt16(CH13A11_R3.Value.ToString())) & 0xff);
                            Send_buf[28] = Convert.ToByte(Convert.ToUInt16(CH13A11_R4.Value.ToString()) >> 8);
                            Send_buf[29] = Convert.ToByte((Convert.ToUInt16(CH13A11_R4.Value.ToString())) & 0xff);
                            Send_buf[30] = Convert.ToByte(Convert.ToUInt16(CH13A11_R5.Value.ToString()) >> 8);
                            Send_buf[31] = Convert.ToByte((Convert.ToUInt16(CH13A11_R5.Value.ToString())) & 0xff);
                            Send_buf[32] = Convert.ToByte(Convert.ToUInt16(CH13A11_R6.Value.ToString()) >> 8);
                            Send_buf[33] = Convert.ToByte((Convert.ToUInt16(CH13A11_R6.Value.ToString())) & 0xff);
                            Send_buf[34] = Convert.ToByte(Convert.ToUInt16(CH13A11_R7.Value.ToString()) >> 8);
                            Send_buf[35] = Convert.ToByte((Convert.ToUInt16(CH13A11_R7.Value.ToString())) & 0xff);
                            Send_buf[36] = Convert.ToByte(Convert.ToUInt16(CH13A11_R8.Value.ToString()) >> 8);
                            Send_buf[37] = Convert.ToByte((Convert.ToUInt16(CH13A11_R8.Value.ToString())) & 0xff);
                            Send_buf[38] = Convert.ToByte(Convert.ToUInt16(CH13A11_R9.Value.ToString()) >> 8);
                            Send_buf[39] = Convert.ToByte((Convert.ToUInt16(CH13A11_R9.Value.ToString())) & 0xff);
                            Send_buf[40] = Convert.ToByte(Convert.ToUInt16(CH13A11_R10.Value.ToString()) >> 8);
                            Send_buf[41] = Convert.ToByte((Convert.ToUInt16(CH13A11_R10.Value.ToString())) & 0xff);
                            Send_buf[42] = Convert.ToByte(Convert.ToUInt16(CH13A11_R11.Value.ToString()) >> 8);
                            Send_buf[43] = Convert.ToByte((Convert.ToUInt16(CH13A11_R11.Value.ToString())) & 0xff);
                            Send_buf[44] = Convert.ToByte(Convert.ToUInt16(CH13A11_R12.Value.ToString()) >> 8);
                            Send_buf[45] = Convert.ToByte((Convert.ToUInt16(CH13A11_R12.Value.ToString())) & 0xff);
                            Send_buf[46] = Convert.ToByte(Convert.ToUInt16(CH13A11_R13.Value.ToString()) >> 8);
                            Send_buf[47] = Convert.ToByte((Convert.ToUInt16(CH13A11_R13.Value.ToString())) & 0xff);
                            Send_buf[48] = Convert.ToByte(Convert.ToUInt16(CH13A11_R14.Value.ToString()) >> 8);
                            Send_buf[49] = Convert.ToByte((Convert.ToUInt16(CH13A11_R14.Value.ToString())) & 0xff);
                            Send_buf[50] = Convert.ToByte(Convert.ToUInt16(CH13A11_R15.Value.ToString()) >> 8);
                            Send_buf[51] = Convert.ToByte((Convert.ToUInt16(CH13A11_R15.Value.ToString())) & 0xff);
                            Send_buf[52] = Convert.ToByte(Convert.ToUInt16(CH13A11_R16.Value.ToString()) >> 8);
                            Send_buf[53] = Convert.ToByte((Convert.ToUInt16(CH13A11_R16.Value.ToString())) & 0xff);
                        }
                        else if (rbt_CH13A11_15points.Checked == true)
                        {
                            Send_buf[24] = Convert.ToByte(Convert.ToUInt16(CH13A11_R0.Value.ToString()) >> 8);//高位，8--10
                            Send_buf[25] = Convert.ToByte((Convert.ToUInt16(CH13A11_R0.Value.ToString())) & 0xff);//低位，0--7
                            Send_buf[26] = Convert.ToByte(Convert.ToUInt16(CH13A11_R1.Value.ToString()) >> 8);
                            Send_buf[27] = Convert.ToByte((Convert.ToUInt16(CH13A11_R1.Value.ToString())) & 0xff);
                            Send_buf[28] = Convert.ToByte(Convert.ToUInt16(CH13A11_R2.Value.ToString()) >> 8);
                            Send_buf[29] = Convert.ToByte((Convert.ToUInt16(CH13A11_R2.Value.ToString())) & 0xff);
                            Send_buf[30] = Convert.ToByte(Convert.ToUInt16(CH13A11_R3.Value.ToString()) >> 8);
                            Send_buf[31] = Convert.ToByte((Convert.ToUInt16(CH13A11_R3.Value.ToString())) & 0xff);
                            Send_buf[32] = Convert.ToByte(Convert.ToUInt16(CH13A11_R4.Value.ToString()) >> 8);
                            Send_buf[33] = Convert.ToByte((Convert.ToUInt16(CH13A11_R4.Value.ToString())) & 0xff);
                            Send_buf[34] = Convert.ToByte(Convert.ToUInt16(CH13A11_R5.Value.ToString()) >> 8);
                            Send_buf[35] = Convert.ToByte((Convert.ToUInt16(CH13A11_R5.Value.ToString())) & 0xff);
                            Send_buf[36] = Convert.ToByte(Convert.ToUInt16(CH13A11_R6.Value.ToString()) >> 8);
                            Send_buf[37] = Convert.ToByte((Convert.ToUInt16(CH13A11_R6.Value.ToString())) & 0xff);
                            Send_buf[38] = Convert.ToByte(Convert.ToUInt16(CH13A11_R7.Value.ToString()) >> 8);
                            Send_buf[39] = Convert.ToByte((Convert.ToUInt16(CH13A11_R7.Value.ToString())) & 0xff);
                            Send_buf[40] = Convert.ToByte(Convert.ToUInt16(CH13A11_R8.Value.ToString()) >> 8);
                            Send_buf[41] = Convert.ToByte((Convert.ToUInt16(CH13A11_R8.Value.ToString())) & 0xff);
                            Send_buf[42] = Convert.ToByte(Convert.ToUInt16(CH13A11_R9.Value.ToString()) >> 8);
                            Send_buf[43] = Convert.ToByte((Convert.ToUInt16(CH13A11_R9.Value.ToString())) & 0xff);
                            Send_buf[44] = Convert.ToByte(Convert.ToUInt16(CH13A11_R10.Value.ToString()) >> 8);
                            Send_buf[45] = Convert.ToByte((Convert.ToUInt16(CH13A11_R10.Value.ToString())) & 0xff);
                            Send_buf[46] = Convert.ToByte(Convert.ToUInt16(CH13A11_R11.Value.ToString()) >> 8);
                            Send_buf[47] = Convert.ToByte((Convert.ToUInt16(CH13A11_R11.Value.ToString())) & 0xff);
                            Send_buf[48] = Convert.ToByte(Convert.ToUInt16(CH13A11_R12.Value.ToString()) >> 8);
                            Send_buf[49] = Convert.ToByte((Convert.ToUInt16(CH13A11_R12.Value.ToString())) & 0xff);
                            Send_buf[50] = Convert.ToByte(Convert.ToUInt16(CH13A11_R13.Value.ToString()) >> 8);
                            Send_buf[51] = Convert.ToByte((Convert.ToUInt16(CH13A11_R13.Value.ToString())) & 0xff);
                            Send_buf[52] = Convert.ToByte(Convert.ToUInt16(CH13A11_R14.Value.ToString()) >> 8);
                            Send_buf[53] = Convert.ToByte((Convert.ToUInt16(CH13A11_R14.Value.ToString())) & 0xff);
                        }
                        else if (rbt_CH13A11_34points.Checked == true)
                        {
                            Send_buf[4] = Convert.ToByte((Convert.ToUInt16(CH13A11_R0.Value.ToString()) >> 8) | ((Convert.ToUInt16(CH13A11_R1.Value.ToString()) >> 8) << 4));
                            Send_buf[5] = Convert.ToByte(Convert.ToUInt16(CH13A11_R0.Value.ToString()) & 0xff);
                            Send_buf[6] = Convert.ToByte(Convert.ToUInt16(CH13A11_R1.Value.ToString()) & 0xff);

                            Send_buf[7] = Convert.ToByte((Convert.ToUInt16(CH13A11_R2.Value.ToString()) >> 8) | ((Convert.ToUInt16(CH13A11_R3.Value.ToString()) >> 8) << 4));
                            Send_buf[8] = Convert.ToByte(Convert.ToUInt16(CH13A11_R2.Value.ToString()) & 0xff);
                            Send_buf[9] = Convert.ToByte(Convert.ToUInt16(CH13A11_R3.Value.ToString()) & 0xff);

                            Send_buf[10] = Convert.ToByte((Convert.ToUInt16(CH13A11_R4.Value.ToString()) >> 8) | ((Convert.ToUInt16(CH13A11_R5.Value.ToString()) >> 8) << 4));
                            Send_buf[11] = Convert.ToByte(Convert.ToUInt16(CH13A11_R4.Value.ToString()) & 0xff);
                            Send_buf[12] = Convert.ToByte(Convert.ToUInt16(CH13A11_R5.Value.ToString()) & 0xff);

                            Send_buf[13] = Convert.ToByte((Convert.ToUInt16(CH13A11_R6.Value.ToString()) >> 8) | ((Convert.ToUInt16(CH13A11_R7.Value.ToString()) >> 8) << 4));
                            Send_buf[14] = Convert.ToByte(Convert.ToUInt16(CH13A11_R6.Value.ToString()) & 0xff);
                            Send_buf[15] = Convert.ToByte(Convert.ToUInt16(CH13A11_R7.Value.ToString()) & 0xff);

                            Send_buf[16] = Convert.ToByte((Convert.ToUInt16(CH13A11_R8.Value.ToString()) >> 8) | ((Convert.ToUInt16(CH13A11_R9.Value.ToString()) >> 8) << 4));
                            Send_buf[17] = Convert.ToByte(Convert.ToUInt16(CH13A11_R8.Value.ToString()) & 0xff);
                            Send_buf[18] = Convert.ToByte(Convert.ToUInt16(CH13A11_R9.Value.ToString()) & 0xff);

                            Send_buf[19] = Convert.ToByte((Convert.ToUInt16(CH13A11_R10.Value.ToString()) >> 8) | ((Convert.ToUInt16(CH13A11_R11.Value.ToString()) >> 8) << 4));
                            Send_buf[20] = Convert.ToByte(Convert.ToUInt16(CH13A11_R10.Value.ToString()) & 0xff);
                            Send_buf[21] = Convert.ToByte(Convert.ToUInt16(CH13A11_R11.Value.ToString()) & 0xff);


                            Send_buf[22] = Convert.ToByte((Convert.ToUInt16(CH13A11_R12.Value.ToString()) >> 8) | ((Convert.ToUInt16(CH13A11_R13.Value.ToString()) >> 8) << 4));
                            Send_buf[23] = Convert.ToByte(Convert.ToUInt16(CH13A11_R12.Value.ToString()) & 0xff);
                            Send_buf[24] = Convert.ToByte(Convert.ToUInt16(CH13A11_R13.Value.ToString()) & 0xff);

                            Send_buf[25] = Convert.ToByte((Convert.ToUInt16(CH13A11_R14.Value.ToString()) >> 8) | ((Convert.ToUInt16(CH13A11_R15.Value.ToString()) >> 8) << 4));
                            Send_buf[26] = Convert.ToByte(Convert.ToUInt16(CH13A11_R14.Value.ToString()) & 0xff);
                            Send_buf[27] = Convert.ToByte(Convert.ToUInt16(CH13A11_R15.Value.ToString()) & 0xff);

                            Send_buf[28] = Convert.ToByte((Convert.ToUInt16(CH13A11_R16.Value.ToString()) >> 8) | ((Convert.ToUInt16(CH13A11_R17.Value.ToString()) >> 8) << 4));
                            Send_buf[29] = Convert.ToByte(Convert.ToUInt16(CH13A11_R16.Value.ToString()) & 0xff);
                            Send_buf[30] = Convert.ToByte(Convert.ToUInt16(CH13A11_R17.Value.ToString()) & 0xff);

                            Send_buf[31] = Convert.ToByte((Convert.ToUInt16(CH13A11_R18.Value.ToString()) >> 8) | ((Convert.ToUInt16(CH13A11_R19.Value.ToString()) >> 8) << 4));
                            Send_buf[32] = Convert.ToByte(Convert.ToUInt16(CH13A11_R18.Value.ToString()) & 0xff);
                            Send_buf[33] = Convert.ToByte(Convert.ToUInt16(CH13A11_R19.Value.ToString()) & 0xff);

                            Send_buf[34] = Convert.ToByte((Convert.ToUInt16(CH13A11_R20.Value.ToString()) >> 8) | ((Convert.ToUInt16(CH13A11_R21.Value.ToString()) >> 8) << 4));
                            Send_buf[35] = Convert.ToByte(Convert.ToUInt16(CH13A11_R20.Value.ToString()) & 0xff);
                            Send_buf[36] = Convert.ToByte(Convert.ToUInt16(CH13A11_R21.Value.ToString()) & 0xff);

                            Send_buf[37] = Convert.ToByte((Convert.ToUInt16(CH13A11_R22.Value.ToString()) >> 8) | ((Convert.ToUInt16(CH13A11_R23.Value.ToString()) >> 8) << 4));
                            Send_buf[38] = Convert.ToByte(Convert.ToUInt16(CH13A11_R22.Value.ToString()) & 0xff);
                            Send_buf[39] = Convert.ToByte(Convert.ToUInt16(CH13A11_R23.Value.ToString()) & 0xff);


                            Send_buf[40] = Convert.ToByte((Convert.ToUInt16(CH13A11_R24.Value.ToString()) >> 8) | ((Convert.ToUInt16(CH13A11_R25.Value.ToString()) >> 8) << 4));
                            Send_buf[41] = Convert.ToByte(Convert.ToUInt16(CH13A11_R24.Value.ToString()) & 0xff);
                            Send_buf[42] = Convert.ToByte(Convert.ToUInt16(CH13A11_R25.Value.ToString()) & 0xff);

                            Send_buf[43] = Convert.ToByte((Convert.ToUInt16(CH13A11_R26.Value.ToString()) >> 8) | ((Convert.ToUInt16(CH13A11_R27.Value.ToString()) >> 8) << 4));
                            Send_buf[44] = Convert.ToByte(Convert.ToUInt16(CH13A11_R26.Value.ToString()) & 0xff);
                            Send_buf[45] = Convert.ToByte(Convert.ToUInt16(CH13A11_R27.Value.ToString()) & 0xff);

                            Send_buf[46] = Convert.ToByte((Convert.ToUInt16(CH13A11_R28.Value.ToString()) >> 8) | ((Convert.ToUInt16(CH13A11_R29.Value.ToString()) >> 8) << 4));
                            Send_buf[47] = Convert.ToByte(Convert.ToUInt16(CH13A11_R28.Value.ToString()) & 0xff);
                            Send_buf[48] = Convert.ToByte(Convert.ToUInt16(CH13A11_R29.Value.ToString()) & 0xff);

                            Send_buf[49] = Convert.ToByte((Convert.ToUInt16(CH13A11_R30.Value.ToString()) >> 8) | ((Convert.ToUInt16(CH13A11_R31.Value.ToString()) >> 8) << 4));
                            Send_buf[50] = Convert.ToByte(Convert.ToUInt16(CH13A11_R30.Value.ToString()) & 0xff);
                            Send_buf[51] = Convert.ToByte(Convert.ToUInt16(CH13A11_R31.Value.ToString()) & 0xff);

                            Send_buf[52] = Convert.ToByte(((Convert.ToUInt16(CH13A11_R32.Value.ToString()) >> 8) | (Convert.ToUInt16(CH13A11_R33.Value.ToString()) >> 8) << 4));
                            Send_buf[53] = Convert.ToByte(Convert.ToUInt16(CH13A11_R32.Value.ToString()) & 0xff);
                            Send_buf[54] = Convert.ToByte(Convert.ToUInt16(CH13A11_R33.Value.ToString()) & 0xff);


                        }
                        /*else if (rbt_CH13A11_19points.Checked == true)
                        {
                            Send_buf[16] = Convert.ToByte(Convert.ToUInt16(CH13A11_R0.Value.ToString()) >> 8);
                            Send_buf[17] = Convert.ToByte((Convert.ToUInt16(CH13A11_R0.Value.ToString())) & 0xff);
                            Send_buf[18] = Convert.ToByte(Convert.ToUInt16(CH13A11_R1.Value.ToString()) >> 8);
                            Send_buf[19] = Convert.ToByte((Convert.ToUInt16(CH13A11_R1.Value.ToString())) & 0xff);
                            Send_buf[20] = Convert.ToByte(Convert.ToUInt16(CH13A11_R2.Value.ToString()) >> 8);
                            Send_buf[21] = Convert.ToByte((Convert.ToUInt16(CH13A11_R2.Value.ToString())) & 0xff);
                            Send_buf[22] = Convert.ToByte(Convert.ToUInt16(CH13A11_R3.Value.ToString()) >> 8);
                            Send_buf[23] = Convert.ToByte((Convert.ToUInt16(CH13A11_R3.Value.ToString())) & 0xff);
                            Send_buf[24] = Convert.ToByte(Convert.ToUInt16(CH13A11_R4.Value.ToString()) >> 8);
                            Send_buf[25] = Convert.ToByte((Convert.ToUInt16(CH13A11_R4.Value.ToString())) & 0xff);
                            Send_buf[26] = Convert.ToByte(Convert.ToUInt16(CH13A11_R5.Value.ToString()) >> 8);
                            Send_buf[27] = Convert.ToByte((Convert.ToUInt16(CH13A11_R5.Value.ToString())) & 0xff);
                            Send_buf[28] = Convert.ToByte(Convert.ToUInt16(CH13A11_R6.Value.ToString()) >> 8);
                            Send_buf[29] = Convert.ToByte((Convert.ToUInt16(CH13A11_R6.Value.ToString())) & 0xff);
                            Send_buf[30] = Convert.ToByte(Convert.ToUInt16(CH13A11_R7.Value.ToString()) >> 8);
                            Send_buf[31] = Convert.ToByte((Convert.ToUInt16(CH13A11_R7.Value.ToString())) & 0xff);
                            Send_buf[32] = Convert.ToByte(Convert.ToUInt16(CH13A11_R8.Value.ToString()) >> 8);
                            Send_buf[33] = Convert.ToByte((Convert.ToUInt16(CH13A11_R8.Value.ToString())) & 0xff);
                            Send_buf[34] = Convert.ToByte(Convert.ToUInt16(CH13A11_R9.Value.ToString()) >> 8);
                            Send_buf[35] = Convert.ToByte((Convert.ToUInt16(CH13A11_R9.Value.ToString())) & 0xff);
                            Send_buf[36] = Convert.ToByte(Convert.ToUInt16(CH13A11_R10.Value.ToString()) >> 8);
                            Send_buf[37] = Convert.ToByte((Convert.ToUInt16(CH13A11_R10.Value.ToString())) & 0xff);
                            Send_buf[38] = Convert.ToByte(Convert.ToUInt16(CH13A11_R11.Value.ToString()) >> 8);
                            Send_buf[39] = Convert.ToByte((Convert.ToUInt16(CH13A11_R11.Value.ToString())) & 0xff);
                            Send_buf[40] = Convert.ToByte(Convert.ToUInt16(CH13A11_R12.Value.ToString()) >> 8);
                            Send_buf[41] = Convert.ToByte((Convert.ToUInt16(CH13A11_R12.Value.ToString())) & 0xff);
                            Send_buf[42] = Convert.ToByte(Convert.ToUInt16(CH13A11_R13.Value.ToString()) >> 8);
                            Send_buf[43] = Convert.ToByte((Convert.ToUInt16(CH13A11_R13.Value.ToString())) & 0xff);
                            Send_buf[44] = Convert.ToByte(Convert.ToUInt16(CH13A11_R14.Value.ToString()) >> 8);
                            Send_buf[45] = Convert.ToByte((Convert.ToUInt16(CH13A11_R14.Value.ToString())) & 0xff);
                            Send_buf[46] = Convert.ToByte(Convert.ToUInt16(CH13A11_R15.Value.ToString()) >> 8);
                            Send_buf[47] = Convert.ToByte((Convert.ToUInt16(CH13A11_R15.Value.ToString())) & 0xff);
                            Send_buf[48] = Convert.ToByte(Convert.ToUInt16(CH13A11_R16.Value.ToString()) >> 8);
                            Send_buf[49] = Convert.ToByte((Convert.ToUInt16(CH13A11_R16.Value.ToString())) & 0xff);
                            Send_buf[50] = Convert.ToByte(Convert.ToUInt16(CH13A11_R17.Value.ToString()) >> 8);
                            Send_buf[51] = Convert.ToByte((Convert.ToUInt16(CH13A11_R17.Value.ToString())) & 0xff);
                            Send_buf[52] = Convert.ToByte(Convert.ToUInt16(CH13A11_R18.Value.ToString()) >> 8);
                            Send_buf[53] = Convert.ToByte((Convert.ToUInt16(CH13A11_R18.Value.ToString())) & 0xff);
                        }
                        */

                    }
                    break;
                case "CH13A11_GammaW_GREEN":
                    {
                        Send_buf[1] = 0x08;
                        Send_buf[3] = 0x02; //GREEN

                        if (rbt_CH13A11_25points.Checked == true)
                        {
                            Send_buf[4] = Convert.ToByte(Convert.ToUInt16(CH13A11_G0.Value.ToString()) >> 8);
                            Send_buf[5] = Convert.ToByte((Convert.ToUInt16(CH13A11_G0.Value.ToString())) & 0xff);
                            Send_buf[6] = Convert.ToByte(Convert.ToUInt16(CH13A11_G1.Value.ToString()) >> 8);
                            Send_buf[7] = Convert.ToByte((Convert.ToUInt16(CH13A11_G1.Value.ToString())) & 0xff);
                            Send_buf[8] = Convert.ToByte(Convert.ToUInt16(CH13A11_G2.Value.ToString()) >> 8);
                            Send_buf[9] = Convert.ToByte((Convert.ToUInt16(CH13A11_G2.Value.ToString())) & 0xff);
                            Send_buf[10] = Convert.ToByte(Convert.ToUInt16(CH13A11_G3.Value.ToString()) >> 8);
                            Send_buf[11] = Convert.ToByte((Convert.ToUInt16(CH13A11_G3.Value.ToString())) & 0xff);
                            Send_buf[12] = Convert.ToByte(Convert.ToUInt16(CH13A11_G4.Value.ToString()) >> 8);
                            Send_buf[13] = Convert.ToByte((Convert.ToUInt16(CH13A11_G4.Value.ToString())) & 0xff);
                            Send_buf[14] = Convert.ToByte(Convert.ToUInt16(CH13A11_G5.Value.ToString()) >> 8);
                            Send_buf[15] = Convert.ToByte((Convert.ToUInt16(CH13A11_G5.Value.ToString())) & 0xff);
                            Send_buf[16] = Convert.ToByte(Convert.ToUInt16(CH13A11_G6.Value.ToString()) >> 8);
                            Send_buf[17] = Convert.ToByte((Convert.ToUInt16(CH13A11_G6.Value.ToString())) & 0xff);
                            Send_buf[18] = Convert.ToByte(Convert.ToUInt16(CH13A11_G7.Value.ToString()) >> 8);
                            Send_buf[19] = Convert.ToByte((Convert.ToUInt16(CH13A11_G7.Value.ToString())) & 0xff);
                            Send_buf[20] = Convert.ToByte(Convert.ToUInt16(CH13A11_G8.Value.ToString()) >> 8);
                            Send_buf[21] = Convert.ToByte((Convert.ToUInt16(CH13A11_G8.Value.ToString())) & 0xff);
                            Send_buf[22] = Convert.ToByte(Convert.ToUInt16(CH13A11_G9.Value.ToString()) >> 8);
                            Send_buf[23] = Convert.ToByte((Convert.ToUInt16(CH13A11_G9.Value.ToString())) & 0xff);
                            Send_buf[24] = Convert.ToByte(Convert.ToUInt16(CH13A11_G10.Value.ToString()) >> 8);
                            Send_buf[25] = Convert.ToByte((Convert.ToUInt16(CH13A11_G10.Value.ToString())) & 0xff);
                            Send_buf[26] = Convert.ToByte(Convert.ToUInt16(CH13A11_G11.Value.ToString()) >> 8);
                            Send_buf[27] = Convert.ToByte((Convert.ToUInt16(CH13A11_G11.Value.ToString())) & 0xff);
                            Send_buf[28] = Convert.ToByte(Convert.ToUInt16(CH13A11_G12.Value.ToString()) >> 8);
                            Send_buf[29] = Convert.ToByte((Convert.ToUInt16(CH13A11_G12.Value.ToString())) & 0xff);
                            Send_buf[30] = Convert.ToByte(Convert.ToUInt16(CH13A11_G13.Value.ToString()) >> 8);
                            Send_buf[31] = Convert.ToByte((Convert.ToUInt16(CH13A11_G13.Value.ToString())) & 0xff);
                            Send_buf[32] = Convert.ToByte(Convert.ToUInt16(CH13A11_G14.Value.ToString()) >> 8);
                            Send_buf[33] = Convert.ToByte((Convert.ToUInt16(CH13A11_G14.Value.ToString())) & 0xff);
                            Send_buf[34] = Convert.ToByte(Convert.ToUInt16(CH13A11_G15.Value.ToString()) >> 8);
                            Send_buf[35] = Convert.ToByte((Convert.ToUInt16(CH13A11_G15.Value.ToString())) & 0xff);
                            Send_buf[36] = Convert.ToByte(Convert.ToUInt16(CH13A11_G16.Value.ToString()) >> 8);
                            Send_buf[37] = Convert.ToByte((Convert.ToUInt16(CH13A11_G16.Value.ToString())) & 0xff);
                            Send_buf[38] = Convert.ToByte(Convert.ToUInt16(CH13A11_G17.Value.ToString()) >> 8);
                            Send_buf[39] = Convert.ToByte((Convert.ToUInt16(CH13A11_G17.Value.ToString())) & 0xff);
                            Send_buf[40] = Convert.ToByte(Convert.ToUInt16(CH13A11_G18.Value.ToString()) >> 8);
                            Send_buf[41] = Convert.ToByte((Convert.ToUInt16(CH13A11_G18.Value.ToString())) & 0xff);
                            Send_buf[42] = Convert.ToByte(Convert.ToUInt16(CH13A11_G19.Value.ToString()) >> 8);
                            Send_buf[43] = Convert.ToByte((Convert.ToUInt16(CH13A11_G19.Value.ToString())) & 0xff);
                            Send_buf[44] = Convert.ToByte(Convert.ToUInt16(CH13A11_G20.Value.ToString()) >> 8);
                            Send_buf[45] = Convert.ToByte((Convert.ToUInt16(CH13A11_G20.Value.ToString())) & 0xff);
                            Send_buf[46] = Convert.ToByte(Convert.ToUInt16(CH13A11_G21.Value.ToString()) >> 8);
                            Send_buf[47] = Convert.ToByte((Convert.ToUInt16(CH13A11_G21.Value.ToString())) & 0xff);
                            Send_buf[48] = Convert.ToByte(Convert.ToUInt16(CH13A11_G22.Value.ToString()) >> 8);
                            Send_buf[49] = Convert.ToByte((Convert.ToUInt16(CH13A11_G22.Value.ToString())) & 0xff);
                            Send_buf[50] = Convert.ToByte(Convert.ToUInt16(CH13A11_G23.Value.ToString()) >> 8);
                            Send_buf[51] = Convert.ToByte((Convert.ToUInt16(CH13A11_G23.Value.ToString())) & 0xff);
                            Send_buf[52] = Convert.ToByte(Convert.ToUInt16(CH13A11_G24.Value.ToString()) >> 8);
                            Send_buf[53] = Convert.ToByte((Convert.ToUInt16(CH13A11_G24.Value.ToString())) & 0xff);
                        }
                        else if (rbt_CH13A11_17points.Checked == true)
                        {
                            Send_buf[20] = Convert.ToByte(Convert.ToUInt16(CH13A11_G0.Value.ToString()) >> 8);//高位，8--10
                            Send_buf[21] = Convert.ToByte((Convert.ToUInt16(CH13A11_G0.Value.ToString())) & 0xff);//低位，0--7
                            Send_buf[22] = Convert.ToByte(Convert.ToUInt16(CH13A11_G1.Value.ToString()) >> 8);
                            Send_buf[23] = Convert.ToByte((Convert.ToUInt16(CH13A11_G1.Value.ToString())) & 0xff);
                            Send_buf[24] = Convert.ToByte(Convert.ToUInt16(CH13A11_G2.Value.ToString()) >> 8);
                            Send_buf[25] = Convert.ToByte((Convert.ToUInt16(CH13A11_G2.Value.ToString())) & 0xff);
                            Send_buf[26] = Convert.ToByte(Convert.ToUInt16(CH13A11_G3.Value.ToString()) >> 8);
                            Send_buf[27] = Convert.ToByte((Convert.ToUInt16(CH13A11_G3.Value.ToString())) & 0xff);
                            Send_buf[28] = Convert.ToByte(Convert.ToUInt16(CH13A11_G4.Value.ToString()) >> 8);
                            Send_buf[29] = Convert.ToByte((Convert.ToUInt16(CH13A11_G4.Value.ToString())) & 0xff);
                            Send_buf[30] = Convert.ToByte(Convert.ToUInt16(CH13A11_G5.Value.ToString()) >> 8);
                            Send_buf[31] = Convert.ToByte((Convert.ToUInt16(CH13A11_G5.Value.ToString())) & 0xff);
                            Send_buf[32] = Convert.ToByte(Convert.ToUInt16(CH13A11_G6.Value.ToString()) >> 8);
                            Send_buf[33] = Convert.ToByte((Convert.ToUInt16(CH13A11_G6.Value.ToString())) & 0xff);
                            Send_buf[34] = Convert.ToByte(Convert.ToUInt16(CH13A11_G7.Value.ToString()) >> 8);
                            Send_buf[35] = Convert.ToByte((Convert.ToUInt16(CH13A11_G7.Value.ToString())) & 0xff);
                            Send_buf[36] = Convert.ToByte(Convert.ToUInt16(CH13A11_G8.Value.ToString()) >> 8);
                            Send_buf[37] = Convert.ToByte((Convert.ToUInt16(CH13A11_G8.Value.ToString())) & 0xff);
                            Send_buf[38] = Convert.ToByte(Convert.ToUInt16(CH13A11_G9.Value.ToString()) >> 8);
                            Send_buf[39] = Convert.ToByte((Convert.ToUInt16(CH13A11_G9.Value.ToString())) & 0xff);
                            Send_buf[40] = Convert.ToByte(Convert.ToUInt16(CH13A11_G10.Value.ToString()) >> 8);
                            Send_buf[41] = Convert.ToByte((Convert.ToUInt16(CH13A11_G10.Value.ToString())) & 0xff);
                            Send_buf[42] = Convert.ToByte(Convert.ToUInt16(CH13A11_G11.Value.ToString()) >> 8);
                            Send_buf[43] = Convert.ToByte((Convert.ToUInt16(CH13A11_G11.Value.ToString())) & 0xff);
                            Send_buf[44] = Convert.ToByte(Convert.ToUInt16(CH13A11_G12.Value.ToString()) >> 8);
                            Send_buf[45] = Convert.ToByte((Convert.ToUInt16(CH13A11_G12.Value.ToString())) & 0xff);
                            Send_buf[46] = Convert.ToByte(Convert.ToUInt16(CH13A11_G13.Value.ToString()) >> 8);
                            Send_buf[47] = Convert.ToByte((Convert.ToUInt16(CH13A11_G13.Value.ToString())) & 0xff);
                            Send_buf[48] = Convert.ToByte(Convert.ToUInt16(CH13A11_G14.Value.ToString()) >> 8);
                            Send_buf[49] = Convert.ToByte((Convert.ToUInt16(CH13A11_G14.Value.ToString())) & 0xff);
                            Send_buf[50] = Convert.ToByte(Convert.ToUInt16(CH13A11_G15.Value.ToString()) >> 8);
                            Send_buf[51] = Convert.ToByte((Convert.ToUInt16(CH13A11_G15.Value.ToString())) & 0xff);
                            Send_buf[52] = Convert.ToByte(Convert.ToUInt16(CH13A11_G16.Value.ToString()) >> 8);
                            Send_buf[53] = Convert.ToByte((Convert.ToUInt16(CH13A11_G16.Value.ToString())) & 0xff);
                        }
                        else if (rbt_CH13A11_15points.Checked == true)
                        {
                            Send_buf[24] = Convert.ToByte(Convert.ToUInt16(CH13A11_G0.Value.ToString()) >> 8);//高位，8--10
                            Send_buf[25] = Convert.ToByte((Convert.ToUInt16(CH13A11_G0.Value.ToString())) & 0xff);//低位，0--7
                            Send_buf[26] = Convert.ToByte(Convert.ToUInt16(CH13A11_G1.Value.ToString()) >> 8);
                            Send_buf[27] = Convert.ToByte((Convert.ToUInt16(CH13A11_G1.Value.ToString())) & 0xff);
                            Send_buf[28] = Convert.ToByte(Convert.ToUInt16(CH13A11_G2.Value.ToString()) >> 8);
                            Send_buf[29] = Convert.ToByte((Convert.ToUInt16(CH13A11_G2.Value.ToString())) & 0xff);
                            Send_buf[30] = Convert.ToByte(Convert.ToUInt16(CH13A11_G3.Value.ToString()) >> 8);
                            Send_buf[31] = Convert.ToByte((Convert.ToUInt16(CH13A11_G3.Value.ToString())) & 0xff);
                            Send_buf[32] = Convert.ToByte(Convert.ToUInt16(CH13A11_G4.Value.ToString()) >> 8);
                            Send_buf[33] = Convert.ToByte((Convert.ToUInt16(CH13A11_G4.Value.ToString())) & 0xff);
                            Send_buf[34] = Convert.ToByte(Convert.ToUInt16(CH13A11_G5.Value.ToString()) >> 8);
                            Send_buf[35] = Convert.ToByte((Convert.ToUInt16(CH13A11_G5.Value.ToString())) & 0xff);
                            Send_buf[36] = Convert.ToByte(Convert.ToUInt16(CH13A11_G6.Value.ToString()) >> 8);
                            Send_buf[37] = Convert.ToByte((Convert.ToUInt16(CH13A11_G6.Value.ToString())) & 0xff);
                            Send_buf[38] = Convert.ToByte(Convert.ToUInt16(CH13A11_G7.Value.ToString()) >> 8);
                            Send_buf[39] = Convert.ToByte((Convert.ToUInt16(CH13A11_G7.Value.ToString())) & 0xff);
                            Send_buf[40] = Convert.ToByte(Convert.ToUInt16(CH13A11_G8.Value.ToString()) >> 8);
                            Send_buf[41] = Convert.ToByte((Convert.ToUInt16(CH13A11_G8.Value.ToString())) & 0xff);
                            Send_buf[42] = Convert.ToByte(Convert.ToUInt16(CH13A11_G9.Value.ToString()) >> 8);
                            Send_buf[43] = Convert.ToByte((Convert.ToUInt16(CH13A11_G9.Value.ToString())) & 0xff);
                            Send_buf[44] = Convert.ToByte(Convert.ToUInt16(CH13A11_G10.Value.ToString()) >> 8);
                            Send_buf[45] = Convert.ToByte((Convert.ToUInt16(CH13A11_G10.Value.ToString())) & 0xff);
                            Send_buf[46] = Convert.ToByte(Convert.ToUInt16(CH13A11_G11.Value.ToString()) >> 8);
                            Send_buf[47] = Convert.ToByte((Convert.ToUInt16(CH13A11_G11.Value.ToString())) & 0xff);
                            Send_buf[48] = Convert.ToByte(Convert.ToUInt16(CH13A11_G12.Value.ToString()) >> 8);
                            Send_buf[49] = Convert.ToByte((Convert.ToUInt16(CH13A11_G12.Value.ToString())) & 0xff);
                            Send_buf[50] = Convert.ToByte(Convert.ToUInt16(CH13A11_G13.Value.ToString()) >> 8);
                            Send_buf[51] = Convert.ToByte((Convert.ToUInt16(CH13A11_G13.Value.ToString())) & 0xff);
                            Send_buf[52] = Convert.ToByte(Convert.ToUInt16(CH13A11_G14.Value.ToString()) >> 8);
                            Send_buf[53] = Convert.ToByte((Convert.ToUInt16(CH13A11_G14.Value.ToString())) & 0xff);
                        }
                        else if (rbt_CH13A11_34points.Checked == true)
                        {
                            Send_buf[4] = Convert.ToByte((Convert.ToUInt16(CH13A11_G0.Value.ToString()) >> 8) | ((Convert.ToUInt16(CH13A11_G1.Value.ToString()) >> 8) << 4));
                            Send_buf[5] = Convert.ToByte(Convert.ToUInt16(CH13A11_G0.Value.ToString()) & 0xff);
                            Send_buf[6] = Convert.ToByte(Convert.ToUInt16(CH13A11_G1.Value.ToString()) & 0xff);

                            Send_buf[7] = Convert.ToByte((Convert.ToUInt16(CH13A11_G2.Value.ToString()) >> 8) | ((Convert.ToUInt16(CH13A11_G3.Value.ToString()) >> 8) << 4));
                            Send_buf[8] = Convert.ToByte(Convert.ToUInt16(CH13A11_G2.Value.ToString()) & 0xff);
                            Send_buf[9] = Convert.ToByte(Convert.ToUInt16(CH13A11_G3.Value.ToString()) & 0xff);

                            Send_buf[10] = Convert.ToByte((Convert.ToUInt16(CH13A11_G4.Value.ToString()) >> 8) | ((Convert.ToUInt16(CH13A11_G5.Value.ToString()) >> 8) << 4));
                            Send_buf[11] = Convert.ToByte(Convert.ToUInt16(CH13A11_G4.Value.ToString()) & 0xff);
                            Send_buf[12] = Convert.ToByte(Convert.ToUInt16(CH13A11_G5.Value.ToString()) & 0xff);

                            Send_buf[13] = Convert.ToByte((Convert.ToUInt16(CH13A11_G6.Value.ToString()) >> 8) | ((Convert.ToUInt16(CH13A11_G7.Value.ToString()) >> 8) << 4));
                            Send_buf[14] = Convert.ToByte(Convert.ToUInt16(CH13A11_G6.Value.ToString()) & 0xff);
                            Send_buf[15] = Convert.ToByte(Convert.ToUInt16(CH13A11_G7.Value.ToString()) & 0xff);

                            Send_buf[16] = Convert.ToByte((Convert.ToUInt16(CH13A11_G8.Value.ToString()) >> 8) | ((Convert.ToUInt16(CH13A11_G9.Value.ToString()) >> 8) << 4));
                            Send_buf[17] = Convert.ToByte(Convert.ToUInt16(CH13A11_G8.Value.ToString()) & 0xff);
                            Send_buf[18] = Convert.ToByte(Convert.ToUInt16(CH13A11_G9.Value.ToString()) & 0xff);

                            Send_buf[19] = Convert.ToByte((Convert.ToUInt16(CH13A11_G10.Value.ToString()) >> 8) | ((Convert.ToUInt16(CH13A11_G11.Value.ToString()) >> 8) << 4));
                            Send_buf[20] = Convert.ToByte(Convert.ToUInt16(CH13A11_G10.Value.ToString()) & 0xff);
                            Send_buf[21] = Convert.ToByte(Convert.ToUInt16(CH13A11_G11.Value.ToString()) & 0xff);


                            Send_buf[22] = Convert.ToByte((Convert.ToUInt16(CH13A11_G12.Value.ToString()) >> 8) | ((Convert.ToUInt16(CH13A11_G13.Value.ToString()) >> 8) << 4));
                            Send_buf[23] = Convert.ToByte(Convert.ToUInt16(CH13A11_G12.Value.ToString()) & 0xff);
                            Send_buf[24] = Convert.ToByte(Convert.ToUInt16(CH13A11_G13.Value.ToString()) & 0xff);

                            Send_buf[25] = Convert.ToByte((Convert.ToUInt16(CH13A11_G14.Value.ToString()) >> 8) | ((Convert.ToUInt16(CH13A11_G15.Value.ToString()) >> 8) << 4));
                            Send_buf[26] = Convert.ToByte(Convert.ToUInt16(CH13A11_G14.Value.ToString()) & 0xff);
                            Send_buf[27] = Convert.ToByte(Convert.ToUInt16(CH13A11_G15.Value.ToString()) & 0xff);

                            Send_buf[28] = Convert.ToByte((Convert.ToUInt16(CH13A11_G16.Value.ToString()) >> 8) | ((Convert.ToUInt16(CH13A11_G17.Value.ToString()) >> 8) << 4));
                            Send_buf[29] = Convert.ToByte(Convert.ToUInt16(CH13A11_G16.Value.ToString()) & 0xff);
                            Send_buf[30] = Convert.ToByte(Convert.ToUInt16(CH13A11_G17.Value.ToString()) & 0xff);

                            Send_buf[31] = Convert.ToByte((Convert.ToUInt16(CH13A11_G18.Value.ToString()) >> 8) | ((Convert.ToUInt16(CH13A11_G19.Value.ToString()) >> 8) << 4));
                            Send_buf[32] = Convert.ToByte(Convert.ToUInt16(CH13A11_G18.Value.ToString()) & 0xff);
                            Send_buf[33] = Convert.ToByte(Convert.ToUInt16(CH13A11_G19.Value.ToString()) & 0xff);

                            Send_buf[34] = Convert.ToByte((Convert.ToUInt16(CH13A11_G20.Value.ToString()) >> 8) | ((Convert.ToUInt16(CH13A11_G21.Value.ToString()) >> 8) << 4));
                            Send_buf[35] = Convert.ToByte(Convert.ToUInt16(CH13A11_G20.Value.ToString()) & 0xff);
                            Send_buf[36] = Convert.ToByte(Convert.ToUInt16(CH13A11_G21.Value.ToString()) & 0xff);

                            Send_buf[37] = Convert.ToByte((Convert.ToUInt16(CH13A11_G22.Value.ToString()) >> 8) | ((Convert.ToUInt16(CH13A11_G23.Value.ToString()) >> 8) << 4));
                            Send_buf[38] = Convert.ToByte(Convert.ToUInt16(CH13A11_G22.Value.ToString()) & 0xff);
                            Send_buf[39] = Convert.ToByte(Convert.ToUInt16(CH13A11_G23.Value.ToString()) & 0xff);


                            Send_buf[40] = Convert.ToByte((Convert.ToUInt16(CH13A11_G24.Value.ToString()) >> 8) | ((Convert.ToUInt16(CH13A11_G25.Value.ToString()) >> 8) << 4));
                            Send_buf[41] = Convert.ToByte(Convert.ToUInt16(CH13A11_G24.Value.ToString()) & 0xff);
                            Send_buf[42] = Convert.ToByte(Convert.ToUInt16(CH13A11_G25.Value.ToString()) & 0xff);

                            Send_buf[43] = Convert.ToByte((Convert.ToUInt16(CH13A11_G26.Value.ToString()) >> 8) | ((Convert.ToUInt16(CH13A11_G27.Value.ToString()) >> 8) << 4));
                            Send_buf[44] = Convert.ToByte(Convert.ToUInt16(CH13A11_G26.Value.ToString()) & 0xff);
                            Send_buf[45] = Convert.ToByte(Convert.ToUInt16(CH13A11_G27.Value.ToString()) & 0xff);

                            Send_buf[46] = Convert.ToByte((Convert.ToUInt16(CH13A11_G28.Value.ToString()) >> 8) | ((Convert.ToUInt16(CH13A11_G29.Value.ToString()) >> 8) << 4));
                            Send_buf[47] = Convert.ToByte(Convert.ToUInt16(CH13A11_G28.Value.ToString()) & 0xff);
                            Send_buf[48] = Convert.ToByte(Convert.ToUInt16(CH13A11_G29.Value.ToString()) & 0xff);

                            Send_buf[49] = Convert.ToByte((Convert.ToUInt16(CH13A11_G30.Value.ToString()) >> 8) | ((Convert.ToUInt16(CH13A11_G31.Value.ToString()) >> 8) << 4));
                            Send_buf[50] = Convert.ToByte(Convert.ToUInt16(CH13A11_G30.Value.ToString()) & 0xff);
                            Send_buf[51] = Convert.ToByte(Convert.ToUInt16(CH13A11_G31.Value.ToString()) & 0xff);

                            Send_buf[52] = Convert.ToByte(((Convert.ToUInt16(CH13A11_G32.Value.ToString()) >> 8) | (Convert.ToUInt16(CH13A11_G33.Value.ToString()) >> 8) << 4));
                            Send_buf[53] = Convert.ToByte(Convert.ToUInt16(CH13A11_G32.Value.ToString()) & 0xff);
                            Send_buf[54] = Convert.ToByte(Convert.ToUInt16(CH13A11_G33.Value.ToString()) & 0xff);
                        }
                        else if (rbt_CH13A11_19points.Checked == true)
                        {
                            Send_buf[16] = Convert.ToByte(Convert.ToUInt16(CH13A11_G0.Value.ToString()) >> 8);
                            Send_buf[17] = Convert.ToByte((Convert.ToUInt16(CH13A11_G0.Value.ToString())) & 0xff);
                            Send_buf[18] = Convert.ToByte(Convert.ToUInt16(CH13A11_G1.Value.ToString()) >> 8);
                            Send_buf[19] = Convert.ToByte((Convert.ToUInt16(CH13A11_G1.Value.ToString())) & 0xff);
                            Send_buf[20] = Convert.ToByte(Convert.ToUInt16(CH13A11_G2.Value.ToString()) >> 8);
                            Send_buf[21] = Convert.ToByte((Convert.ToUInt16(CH13A11_G2.Value.ToString())) & 0xff);
                            Send_buf[22] = Convert.ToByte(Convert.ToUInt16(CH13A11_G3.Value.ToString()) >> 8);
                            Send_buf[23] = Convert.ToByte((Convert.ToUInt16(CH13A11_G3.Value.ToString())) & 0xff);
                            Send_buf[24] = Convert.ToByte(Convert.ToUInt16(CH13A11_G4.Value.ToString()) >> 8);
                            Send_buf[25] = Convert.ToByte((Convert.ToUInt16(CH13A11_G4.Value.ToString())) & 0xff);
                            Send_buf[26] = Convert.ToByte(Convert.ToUInt16(CH13A11_G5.Value.ToString()) >> 8);
                            Send_buf[27] = Convert.ToByte((Convert.ToUInt16(CH13A11_G5.Value.ToString())) & 0xff);
                            Send_buf[28] = Convert.ToByte(Convert.ToUInt16(CH13A11_G6.Value.ToString()) >> 8);
                            Send_buf[29] = Convert.ToByte((Convert.ToUInt16(CH13A11_G6.Value.ToString())) & 0xff);
                            Send_buf[30] = Convert.ToByte(Convert.ToUInt16(CH13A11_G7.Value.ToString()) >> 8);
                            Send_buf[31] = Convert.ToByte((Convert.ToUInt16(CH13A11_G7.Value.ToString())) & 0xff);
                            Send_buf[32] = Convert.ToByte(Convert.ToUInt16(CH13A11_G8.Value.ToString()) >> 8);
                            Send_buf[33] = Convert.ToByte((Convert.ToUInt16(CH13A11_G8.Value.ToString())) & 0xff);
                            Send_buf[34] = Convert.ToByte(Convert.ToUInt16(CH13A11_G9.Value.ToString()) >> 8);
                            Send_buf[35] = Convert.ToByte((Convert.ToUInt16(CH13A11_G9.Value.ToString())) & 0xff);
                            Send_buf[36] = Convert.ToByte(Convert.ToUInt16(CH13A11_G10.Value.ToString()) >> 8);
                            Send_buf[37] = Convert.ToByte((Convert.ToUInt16(CH13A11_G10.Value.ToString())) & 0xff);
                            Send_buf[38] = Convert.ToByte(Convert.ToUInt16(CH13A11_G11.Value.ToString()) >> 8);
                            Send_buf[39] = Convert.ToByte((Convert.ToUInt16(CH13A11_G11.Value.ToString())) & 0xff);
                            Send_buf[40] = Convert.ToByte(Convert.ToUInt16(CH13A11_G12.Value.ToString()) >> 8);
                            Send_buf[41] = Convert.ToByte((Convert.ToUInt16(CH13A11_G12.Value.ToString())) & 0xff);
                            Send_buf[42] = Convert.ToByte(Convert.ToUInt16(CH13A11_G13.Value.ToString()) >> 8);
                            Send_buf[43] = Convert.ToByte((Convert.ToUInt16(CH13A11_G13.Value.ToString())) & 0xff);
                            Send_buf[44] = Convert.ToByte(Convert.ToUInt16(CH13A11_G14.Value.ToString()) >> 8);
                            Send_buf[45] = Convert.ToByte((Convert.ToUInt16(CH13A11_G14.Value.ToString())) & 0xff);
                            Send_buf[46] = Convert.ToByte(Convert.ToUInt16(CH13A11_G15.Value.ToString()) >> 8);
                            Send_buf[47] = Convert.ToByte((Convert.ToUInt16(CH13A11_G15.Value.ToString())) & 0xff);
                            Send_buf[48] = Convert.ToByte(Convert.ToUInt16(CH13A11_G16.Value.ToString()) >> 8);
                            Send_buf[49] = Convert.ToByte((Convert.ToUInt16(CH13A11_G16.Value.ToString())) & 0xff);
                            Send_buf[50] = Convert.ToByte(Convert.ToUInt16(CH13A11_G17.Value.ToString()) >> 8);
                            Send_buf[51] = Convert.ToByte((Convert.ToUInt16(CH13A11_G17.Value.ToString())) & 0xff);
                            Send_buf[52] = Convert.ToByte(Convert.ToUInt16(CH13A11_G18.Value.ToString()) >> 8);
                            Send_buf[53] = Convert.ToByte((Convert.ToUInt16(CH13A11_G18.Value.ToString())) & 0xff);
                        }
                    }
                    break;
                case "CH13A11_GammaW_BLUE":
                    {
                        Send_buf[1] = 0x08;
                        Send_buf[3] = 0x03; //BLUE

                        if (rbt_CH13A11_25points.Checked == true)
                        {
                            Send_buf[4] = Convert.ToByte(Convert.ToUInt16(CH13A11_B0.Value.ToString()) >> 8);
                            Send_buf[5] = Convert.ToByte((Convert.ToUInt16(CH13A11_B0.Value.ToString())) & 0xff);
                            Send_buf[6] = Convert.ToByte(Convert.ToUInt16(CH13A11_B1.Value.ToString()) >> 8);
                            Send_buf[7] = Convert.ToByte((Convert.ToUInt16(CH13A11_B1.Value.ToString())) & 0xff);
                            Send_buf[8] = Convert.ToByte(Convert.ToUInt16(CH13A11_B2.Value.ToString()) >> 8);
                            Send_buf[9] = Convert.ToByte((Convert.ToUInt16(CH13A11_B2.Value.ToString())) & 0xff);
                            Send_buf[10] = Convert.ToByte(Convert.ToUInt16(CH13A11_B3.Value.ToString()) >> 8);
                            Send_buf[11] = Convert.ToByte((Convert.ToUInt16(CH13A11_B3.Value.ToString())) & 0xff);
                            Send_buf[12] = Convert.ToByte(Convert.ToUInt16(CH13A11_B4.Value.ToString()) >> 8);
                            Send_buf[13] = Convert.ToByte((Convert.ToUInt16(CH13A11_B4.Value.ToString())) & 0xff);
                            Send_buf[14] = Convert.ToByte(Convert.ToUInt16(CH13A11_B5.Value.ToString()) >> 8);
                            Send_buf[15] = Convert.ToByte((Convert.ToUInt16(CH13A11_B5.Value.ToString())) & 0xff);
                            Send_buf[16] = Convert.ToByte(Convert.ToUInt16(CH13A11_B6.Value.ToString()) >> 8);
                            Send_buf[17] = Convert.ToByte((Convert.ToUInt16(CH13A11_B6.Value.ToString())) & 0xff);
                            Send_buf[18] = Convert.ToByte(Convert.ToUInt16(CH13A11_B7.Value.ToString()) >> 8);
                            Send_buf[19] = Convert.ToByte((Convert.ToUInt16(CH13A11_B7.Value.ToString())) & 0xff);
                            Send_buf[20] = Convert.ToByte(Convert.ToUInt16(CH13A11_B8.Value.ToString()) >> 8);
                            Send_buf[21] = Convert.ToByte((Convert.ToUInt16(CH13A11_B8.Value.ToString())) & 0xff);
                            Send_buf[22] = Convert.ToByte(Convert.ToUInt16(CH13A11_B9.Value.ToString()) >> 8);
                            Send_buf[23] = Convert.ToByte((Convert.ToUInt16(CH13A11_B9.Value.ToString())) & 0xff);
                            Send_buf[24] = Convert.ToByte(Convert.ToUInt16(CH13A11_B10.Value.ToString()) >> 8);
                            Send_buf[25] = Convert.ToByte((Convert.ToUInt16(CH13A11_B10.Value.ToString())) & 0xff);
                            Send_buf[26] = Convert.ToByte(Convert.ToUInt16(CH13A11_B11.Value.ToString()) >> 8);
                            Send_buf[27] = Convert.ToByte((Convert.ToUInt16(CH13A11_B11.Value.ToString())) & 0xff);
                            Send_buf[28] = Convert.ToByte(Convert.ToUInt16(CH13A11_B12.Value.ToString()) >> 8);
                            Send_buf[29] = Convert.ToByte((Convert.ToUInt16(CH13A11_B12.Value.ToString())) & 0xff);
                            Send_buf[30] = Convert.ToByte(Convert.ToUInt16(CH13A11_B13.Value.ToString()) >> 8);
                            Send_buf[31] = Convert.ToByte((Convert.ToUInt16(CH13A11_B13.Value.ToString())) & 0xff);
                            Send_buf[32] = Convert.ToByte(Convert.ToUInt16(CH13A11_B14.Value.ToString()) >> 8);
                            Send_buf[33] = Convert.ToByte((Convert.ToUInt16(CH13A11_B14.Value.ToString())) & 0xff);
                            Send_buf[34] = Convert.ToByte(Convert.ToUInt16(CH13A11_B15.Value.ToString()) >> 8);
                            Send_buf[35] = Convert.ToByte((Convert.ToUInt16(CH13A11_B15.Value.ToString())) & 0xff);
                            Send_buf[36] = Convert.ToByte(Convert.ToUInt16(CH13A11_B16.Value.ToString()) >> 8);
                            Send_buf[37] = Convert.ToByte((Convert.ToUInt16(CH13A11_B16.Value.ToString())) & 0xff);
                            Send_buf[38] = Convert.ToByte(Convert.ToUInt16(CH13A11_B17.Value.ToString()) >> 8);
                            Send_buf[39] = Convert.ToByte((Convert.ToUInt16(CH13A11_B17.Value.ToString())) & 0xff);
                            Send_buf[40] = Convert.ToByte(Convert.ToUInt16(CH13A11_B18.Value.ToString()) >> 8);
                            Send_buf[41] = Convert.ToByte((Convert.ToUInt16(CH13A11_B18.Value.ToString())) & 0xff);
                            Send_buf[42] = Convert.ToByte(Convert.ToUInt16(CH13A11_B19.Value.ToString()) >> 8);
                            Send_buf[43] = Convert.ToByte((Convert.ToUInt16(CH13A11_B19.Value.ToString())) & 0xff);
                            Send_buf[44] = Convert.ToByte(Convert.ToUInt16(CH13A11_B20.Value.ToString()) >> 8);
                            Send_buf[45] = Convert.ToByte((Convert.ToUInt16(CH13A11_B20.Value.ToString())) & 0xff);
                            Send_buf[46] = Convert.ToByte(Convert.ToUInt16(CH13A11_B21.Value.ToString()) >> 8);
                            Send_buf[47] = Convert.ToByte((Convert.ToUInt16(CH13A11_B21.Value.ToString())) & 0xff);
                            Send_buf[48] = Convert.ToByte(Convert.ToUInt16(CH13A11_B22.Value.ToString()) >> 8);
                            Send_buf[49] = Convert.ToByte((Convert.ToUInt16(CH13A11_B22.Value.ToString())) & 0xff);
                            Send_buf[50] = Convert.ToByte(Convert.ToUInt16(CH13A11_B23.Value.ToString()) >> 8);
                            Send_buf[51] = Convert.ToByte((Convert.ToUInt16(CH13A11_B23.Value.ToString())) & 0xff);
                            Send_buf[52] = Convert.ToByte(Convert.ToUInt16(CH13A11_B24.Value.ToString()) >> 8);
                            Send_buf[53] = Convert.ToByte((Convert.ToUInt16(CH13A11_B24.Value.ToString())) & 0xff);
                        }
                        else if (rbt_CH13A11_17points.Checked == true)
                        {
                            Send_buf[20] = Convert.ToByte(Convert.ToUInt16(CH13A11_B0.Value.ToString()) >> 8);
                            Send_buf[21] = Convert.ToByte((Convert.ToUInt16(CH13A11_B0.Value.ToString())) & 0xff);
                            Send_buf[22] = Convert.ToByte(Convert.ToUInt16(CH13A11_B1.Value.ToString()) >> 8);
                            Send_buf[23] = Convert.ToByte((Convert.ToUInt16(CH13A11_B1.Value.ToString())) & 0xff);
                            Send_buf[24] = Convert.ToByte(Convert.ToUInt16(CH13A11_B2.Value.ToString()) >> 8);
                            Send_buf[25] = Convert.ToByte((Convert.ToUInt16(CH13A11_B2.Value.ToString())) & 0xff);
                            Send_buf[26] = Convert.ToByte(Convert.ToUInt16(CH13A11_B3.Value.ToString()) >> 8);
                            Send_buf[27] = Convert.ToByte((Convert.ToUInt16(CH13A11_B3.Value.ToString())) & 0xff);
                            Send_buf[28] = Convert.ToByte(Convert.ToUInt16(CH13A11_B4.Value.ToString()) >> 8);
                            Send_buf[29] = Convert.ToByte((Convert.ToUInt16(CH13A11_B4.Value.ToString())) & 0xff);
                            Send_buf[30] = Convert.ToByte(Convert.ToUInt16(CH13A11_B5.Value.ToString()) >> 8);
                            Send_buf[31] = Convert.ToByte((Convert.ToUInt16(CH13A11_B5.Value.ToString())) & 0xff);
                            Send_buf[32] = Convert.ToByte(Convert.ToUInt16(CH13A11_B6.Value.ToString()) >> 8);
                            Send_buf[33] = Convert.ToByte((Convert.ToUInt16(CH13A11_B6.Value.ToString())) & 0xff);
                            Send_buf[34] = Convert.ToByte(Convert.ToUInt16(CH13A11_B7.Value.ToString()) >> 8);
                            Send_buf[35] = Convert.ToByte((Convert.ToUInt16(CH13A11_B7.Value.ToString())) & 0xff);
                            Send_buf[36] = Convert.ToByte(Convert.ToUInt16(CH13A11_B8.Value.ToString()) >> 8);
                            Send_buf[37] = Convert.ToByte((Convert.ToUInt16(CH13A11_B8.Value.ToString())) & 0xff);
                            Send_buf[38] = Convert.ToByte(Convert.ToUInt16(CH13A11_B9.Value.ToString()) >> 8);
                            Send_buf[39] = Convert.ToByte((Convert.ToUInt16(CH13A11_B9.Value.ToString())) & 0xff);
                            Send_buf[40] = Convert.ToByte(Convert.ToUInt16(CH13A11_B10.Value.ToString()) >> 8);
                            Send_buf[41] = Convert.ToByte((Convert.ToUInt16(CH13A11_B10.Value.ToString())) & 0xff);
                            Send_buf[42] = Convert.ToByte(Convert.ToUInt16(CH13A11_B11.Value.ToString()) >> 8);
                            Send_buf[43] = Convert.ToByte((Convert.ToUInt16(CH13A11_B11.Value.ToString())) & 0xff);
                            Send_buf[44] = Convert.ToByte(Convert.ToUInt16(CH13A11_B12.Value.ToString()) >> 8);
                            Send_buf[45] = Convert.ToByte((Convert.ToUInt16(CH13A11_B12.Value.ToString())) & 0xff);
                            Send_buf[46] = Convert.ToByte(Convert.ToUInt16(CH13A11_B13.Value.ToString()) >> 8);
                            Send_buf[47] = Convert.ToByte((Convert.ToUInt16(CH13A11_B13.Value.ToString())) & 0xff);
                            Send_buf[48] = Convert.ToByte(Convert.ToUInt16(CH13A11_B14.Value.ToString()) >> 8);
                            Send_buf[49] = Convert.ToByte((Convert.ToUInt16(CH13A11_B14.Value.ToString())) & 0xff);
                            Send_buf[50] = Convert.ToByte(Convert.ToUInt16(CH13A11_B15.Value.ToString()) >> 8);
                            Send_buf[51] = Convert.ToByte((Convert.ToUInt16(CH13A11_B15.Value.ToString())) & 0xff);
                            Send_buf[52] = Convert.ToByte(Convert.ToUInt16(CH13A11_B16.Value.ToString()) >> 8);
                            Send_buf[53] = Convert.ToByte((Convert.ToUInt16(CH13A11_B16.Value.ToString())) & 0xff);
                        }
                        else if (rbt_CH13A11_15points.Checked == true)
                        {
                            Send_buf[24] = Convert.ToByte(Convert.ToUInt16(CH13A11_B0.Value.ToString()) >> 8);//高位，8--10
                            Send_buf[25] = Convert.ToByte((Convert.ToUInt16(CH13A11_B0.Value.ToString())) & 0xff);//低位，0--7
                            Send_buf[26] = Convert.ToByte(Convert.ToUInt16(CH13A11_B1.Value.ToString()) >> 8);
                            Send_buf[27] = Convert.ToByte((Convert.ToUInt16(CH13A11_B1.Value.ToString())) & 0xff);
                            Send_buf[28] = Convert.ToByte(Convert.ToUInt16(CH13A11_B2.Value.ToString()) >> 8);
                            Send_buf[29] = Convert.ToByte((Convert.ToUInt16(CH13A11_B2.Value.ToString())) & 0xff);
                            Send_buf[30] = Convert.ToByte(Convert.ToUInt16(CH13A11_B3.Value.ToString()) >> 8);
                            Send_buf[31] = Convert.ToByte((Convert.ToUInt16(CH13A11_B3.Value.ToString())) & 0xff);
                            Send_buf[32] = Convert.ToByte(Convert.ToUInt16(CH13A11_B4.Value.ToString()) >> 8);
                            Send_buf[33] = Convert.ToByte((Convert.ToUInt16(CH13A11_B4.Value.ToString())) & 0xff);
                            Send_buf[34] = Convert.ToByte(Convert.ToUInt16(CH13A11_B5.Value.ToString()) >> 8);
                            Send_buf[35] = Convert.ToByte((Convert.ToUInt16(CH13A11_B5.Value.ToString())) & 0xff);
                            Send_buf[36] = Convert.ToByte(Convert.ToUInt16(CH13A11_B6.Value.ToString()) >> 8);
                            Send_buf[37] = Convert.ToByte((Convert.ToUInt16(CH13A11_B6.Value.ToString())) & 0xff);
                            Send_buf[38] = Convert.ToByte(Convert.ToUInt16(CH13A11_B7.Value.ToString()) >> 8);
                            Send_buf[39] = Convert.ToByte((Convert.ToUInt16(CH13A11_B7.Value.ToString())) & 0xff);
                            Send_buf[40] = Convert.ToByte(Convert.ToUInt16(CH13A11_B8.Value.ToString()) >> 8);
                            Send_buf[41] = Convert.ToByte((Convert.ToUInt16(CH13A11_B8.Value.ToString())) & 0xff);
                            Send_buf[42] = Convert.ToByte(Convert.ToUInt16(CH13A11_B9.Value.ToString()) >> 8);
                            Send_buf[43] = Convert.ToByte((Convert.ToUInt16(CH13A11_B9.Value.ToString())) & 0xff);
                            Send_buf[44] = Convert.ToByte(Convert.ToUInt16(CH13A11_B10.Value.ToString()) >> 8);
                            Send_buf[45] = Convert.ToByte((Convert.ToUInt16(CH13A11_B10.Value.ToString())) & 0xff);
                            Send_buf[46] = Convert.ToByte(Convert.ToUInt16(CH13A11_B11.Value.ToString()) >> 8);
                            Send_buf[47] = Convert.ToByte((Convert.ToUInt16(CH13A11_B11.Value.ToString())) & 0xff);
                            Send_buf[48] = Convert.ToByte(Convert.ToUInt16(CH13A11_B12.Value.ToString()) >> 8);
                            Send_buf[49] = Convert.ToByte((Convert.ToUInt16(CH13A11_B12.Value.ToString())) & 0xff);
                            Send_buf[50] = Convert.ToByte(Convert.ToUInt16(CH13A11_B13.Value.ToString()) >> 8);
                            Send_buf[51] = Convert.ToByte((Convert.ToUInt16(CH13A11_B13.Value.ToString())) & 0xff);
                            Send_buf[52] = Convert.ToByte(Convert.ToUInt16(CH13A11_B14.Value.ToString()) >> 8);
                            Send_buf[53] = Convert.ToByte((Convert.ToUInt16(CH13A11_B14.Value.ToString())) & 0xff);

                        }
                        else if (rbt_CH13A11_34points.Checked == true)
                        {
                            Send_buf[4] = Convert.ToByte((Convert.ToUInt16(CH13A11_B0.Value.ToString()) >> 8) | ((Convert.ToUInt16(CH13A11_B1.Value.ToString()) >> 8) << 4));
                            Send_buf[5] = Convert.ToByte(Convert.ToUInt16(CH13A11_B0.Value.ToString()) & 0xff);
                            Send_buf[6] = Convert.ToByte(Convert.ToUInt16(CH13A11_B1.Value.ToString()) & 0xff);

                            Send_buf[7] = Convert.ToByte((Convert.ToUInt16(CH13A11_B2.Value.ToString()) >> 8) | ((Convert.ToUInt16(CH13A11_B3.Value.ToString()) >> 8) << 4));
                            Send_buf[8] = Convert.ToByte(Convert.ToUInt16(CH13A11_B2.Value.ToString()) & 0xff);
                            Send_buf[9] = Convert.ToByte(Convert.ToUInt16(CH13A11_B3.Value.ToString()) & 0xff);

                            Send_buf[10] = Convert.ToByte((Convert.ToUInt16(CH13A11_B4.Value.ToString()) >> 8) | ((Convert.ToUInt16(CH13A11_B5.Value.ToString()) >> 8) << 4));
                            Send_buf[11] = Convert.ToByte(Convert.ToUInt16(CH13A11_B4.Value.ToString()) & 0xff);
                            Send_buf[12] = Convert.ToByte(Convert.ToUInt16(CH13A11_B5.Value.ToString()) & 0xff);

                            Send_buf[13] = Convert.ToByte((Convert.ToUInt16(CH13A11_B6.Value.ToString()) >> 8) | ((Convert.ToUInt16(CH13A11_B7.Value.ToString()) >> 8) << 4));
                            Send_buf[14] = Convert.ToByte(Convert.ToUInt16(CH13A11_B6.Value.ToString()) & 0xff);
                            Send_buf[15] = Convert.ToByte(Convert.ToUInt16(CH13A11_B7.Value.ToString()) & 0xff);

                            Send_buf[16] = Convert.ToByte((Convert.ToUInt16(CH13A11_B8.Value.ToString()) >> 8) | ((Convert.ToUInt16(CH13A11_B9.Value.ToString()) >> 8) << 4));
                            Send_buf[17] = Convert.ToByte(Convert.ToUInt16(CH13A11_B8.Value.ToString()) & 0xff);
                            Send_buf[18] = Convert.ToByte(Convert.ToUInt16(CH13A11_B9.Value.ToString()) & 0xff);

                            Send_buf[19] = Convert.ToByte((Convert.ToUInt16(CH13A11_B10.Value.ToString()) >> 8) | ((Convert.ToUInt16(CH13A11_B11.Value.ToString()) >> 8) << 4));
                            Send_buf[20] = Convert.ToByte(Convert.ToUInt16(CH13A11_B10.Value.ToString()) & 0xff);
                            Send_buf[21] = Convert.ToByte(Convert.ToUInt16(CH13A11_B11.Value.ToString()) & 0xff);


                            Send_buf[22] = Convert.ToByte((Convert.ToUInt16(CH13A11_B12.Value.ToString()) >> 8) | ((Convert.ToUInt16(CH13A11_B13.Value.ToString()) >> 8) << 4));
                            Send_buf[23] = Convert.ToByte(Convert.ToUInt16(CH13A11_B12.Value.ToString()) & 0xff);
                            Send_buf[24] = Convert.ToByte(Convert.ToUInt16(CH13A11_B13.Value.ToString()) & 0xff);

                            Send_buf[25] = Convert.ToByte((Convert.ToUInt16(CH13A11_B14.Value.ToString()) >> 8) | ((Convert.ToUInt16(CH13A11_B15.Value.ToString()) >> 8) << 4));
                            Send_buf[26] = Convert.ToByte(Convert.ToUInt16(CH13A11_B14.Value.ToString()) & 0xff);
                            Send_buf[27] = Convert.ToByte(Convert.ToUInt16(CH13A11_B15.Value.ToString()) & 0xff);

                            Send_buf[28] = Convert.ToByte((Convert.ToUInt16(CH13A11_B16.Value.ToString()) >> 8) | ((Convert.ToUInt16(CH13A11_B17.Value.ToString()) >> 8) << 4));
                            Send_buf[29] = Convert.ToByte(Convert.ToUInt16(CH13A11_B16.Value.ToString()) & 0xff);
                            Send_buf[30] = Convert.ToByte(Convert.ToUInt16(CH13A11_B17.Value.ToString()) & 0xff);

                            Send_buf[31] = Convert.ToByte((Convert.ToUInt16(CH13A11_B18.Value.ToString()) >> 8) | ((Convert.ToUInt16(CH13A11_B19.Value.ToString()) >> 8) << 4));
                            Send_buf[32] = Convert.ToByte(Convert.ToUInt16(CH13A11_B18.Value.ToString()) & 0xff);
                            Send_buf[33] = Convert.ToByte(Convert.ToUInt16(CH13A11_B19.Value.ToString()) & 0xff);

                            Send_buf[34] = Convert.ToByte((Convert.ToUInt16(CH13A11_B20.Value.ToString()) >> 8) | ((Convert.ToUInt16(CH13A11_B21.Value.ToString()) >> 8) << 4));
                            Send_buf[35] = Convert.ToByte(Convert.ToUInt16(CH13A11_B20.Value.ToString()) & 0xff);
                            Send_buf[36] = Convert.ToByte(Convert.ToUInt16(CH13A11_B21.Value.ToString()) & 0xff);

                            Send_buf[37] = Convert.ToByte((Convert.ToUInt16(CH13A11_B22.Value.ToString()) >> 8) | ((Convert.ToUInt16(CH13A11_B23.Value.ToString()) >> 8) << 4));
                            Send_buf[38] = Convert.ToByte(Convert.ToUInt16(CH13A11_B22.Value.ToString()) & 0xff);
                            Send_buf[39] = Convert.ToByte(Convert.ToUInt16(CH13A11_B23.Value.ToString()) & 0xff);


                            Send_buf[40] = Convert.ToByte((Convert.ToUInt16(CH13A11_B24.Value.ToString()) >> 8) | ((Convert.ToUInt16(CH13A11_B25.Value.ToString()) >> 8) << 4));
                            Send_buf[41] = Convert.ToByte(Convert.ToUInt16(CH13A11_B24.Value.ToString()) & 0xff);
                            Send_buf[42] = Convert.ToByte(Convert.ToUInt16(CH13A11_B25.Value.ToString()) & 0xff);

                            Send_buf[43] = Convert.ToByte((Convert.ToUInt16(CH13A11_B26.Value.ToString()) >> 8) | ((Convert.ToUInt16(CH13A11_B27.Value.ToString()) >> 8) << 4));
                            Send_buf[44] = Convert.ToByte(Convert.ToUInt16(CH13A11_B26.Value.ToString()) & 0xff);
                            Send_buf[45] = Convert.ToByte(Convert.ToUInt16(CH13A11_B27.Value.ToString()) & 0xff);

                            Send_buf[46] = Convert.ToByte((Convert.ToUInt16(CH13A11_B28.Value.ToString()) >> 8) | ((Convert.ToUInt16(CH13A11_B29.Value.ToString()) >> 8) << 4));
                            Send_buf[47] = Convert.ToByte(Convert.ToUInt16(CH13A11_B28.Value.ToString()) & 0xff);
                            Send_buf[48] = Convert.ToByte(Convert.ToUInt16(CH13A11_B29.Value.ToString()) & 0xff);

                            Send_buf[49] = Convert.ToByte((Convert.ToUInt16(CH13A11_B30.Value.ToString()) >> 8) | ((Convert.ToUInt16(CH13A11_B31.Value.ToString()) >> 8) << 4));
                            Send_buf[50] = Convert.ToByte(Convert.ToUInt16(CH13A11_B30.Value.ToString()) & 0xff);
                            Send_buf[51] = Convert.ToByte(Convert.ToUInt16(CH13A11_B31.Value.ToString()) & 0xff);

                            Send_buf[52] = Convert.ToByte(((Convert.ToUInt16(CH13A11_B32.Value.ToString()) >> 8) | (Convert.ToUInt16(CH13A11_B33.Value.ToString()) >> 8) << 4));
                            Send_buf[53] = Convert.ToByte(Convert.ToUInt16(CH13A11_B32.Value.ToString()) & 0xff);
                            Send_buf[54] = Convert.ToByte(Convert.ToUInt16(CH13A11_B33.Value.ToString()) & 0xff);
                        }
                        else if (rbt_CH13A11_19points.Checked == true)
                        {
                            Send_buf[16] = Convert.ToByte(Convert.ToUInt16(CH13A11_B0.Value.ToString()) >> 8);
                            Send_buf[17] = Convert.ToByte((Convert.ToUInt16(CH13A11_B0.Value.ToString())) & 0xff);
                            Send_buf[18] = Convert.ToByte(Convert.ToUInt16(CH13A11_B1.Value.ToString()) >> 8);
                            Send_buf[19] = Convert.ToByte((Convert.ToUInt16(CH13A11_B1.Value.ToString())) & 0xff);
                            Send_buf[20] = Convert.ToByte(Convert.ToUInt16(CH13A11_B2.Value.ToString()) >> 8);
                            Send_buf[21] = Convert.ToByte((Convert.ToUInt16(CH13A11_B2.Value.ToString())) & 0xff);
                            Send_buf[22] = Convert.ToByte(Convert.ToUInt16(CH13A11_B3.Value.ToString()) >> 8);
                            Send_buf[23] = Convert.ToByte((Convert.ToUInt16(CH13A11_B3.Value.ToString())) & 0xff);
                            Send_buf[24] = Convert.ToByte(Convert.ToUInt16(CH13A11_B4.Value.ToString()) >> 8);
                            Send_buf[25] = Convert.ToByte((Convert.ToUInt16(CH13A11_B4.Value.ToString())) & 0xff);
                            Send_buf[26] = Convert.ToByte(Convert.ToUInt16(CH13A11_B5.Value.ToString()) >> 8);
                            Send_buf[27] = Convert.ToByte((Convert.ToUInt16(CH13A11_B5.Value.ToString())) & 0xff);
                            Send_buf[28] = Convert.ToByte(Convert.ToUInt16(CH13A11_B6.Value.ToString()) >> 8);
                            Send_buf[29] = Convert.ToByte((Convert.ToUInt16(CH13A11_B6.Value.ToString())) & 0xff);
                            Send_buf[30] = Convert.ToByte(Convert.ToUInt16(CH13A11_B7.Value.ToString()) >> 8);
                            Send_buf[31] = Convert.ToByte((Convert.ToUInt16(CH13A11_B7.Value.ToString())) & 0xff);
                            Send_buf[32] = Convert.ToByte(Convert.ToUInt16(CH13A11_B8.Value.ToString()) >> 8);
                            Send_buf[33] = Convert.ToByte((Convert.ToUInt16(CH13A11_B8.Value.ToString())) & 0xff);
                            Send_buf[34] = Convert.ToByte(Convert.ToUInt16(CH13A11_B9.Value.ToString()) >> 8);
                            Send_buf[35] = Convert.ToByte((Convert.ToUInt16(CH13A11_B9.Value.ToString())) & 0xff);
                            Send_buf[36] = Convert.ToByte(Convert.ToUInt16(CH13A11_B10.Value.ToString()) >> 8);
                            Send_buf[37] = Convert.ToByte((Convert.ToUInt16(CH13A11_B10.Value.ToString())) & 0xff);
                            Send_buf[38] = Convert.ToByte(Convert.ToUInt16(CH13A11_B11.Value.ToString()) >> 8);
                            Send_buf[39] = Convert.ToByte((Convert.ToUInt16(CH13A11_B11.Value.ToString())) & 0xff);
                            Send_buf[40] = Convert.ToByte(Convert.ToUInt16(CH13A11_B12.Value.ToString()) >> 8);
                            Send_buf[41] = Convert.ToByte((Convert.ToUInt16(CH13A11_B12.Value.ToString())) & 0xff);
                            Send_buf[42] = Convert.ToByte(Convert.ToUInt16(CH13A11_B13.Value.ToString()) >> 8);
                            Send_buf[43] = Convert.ToByte((Convert.ToUInt16(CH13A11_B13.Value.ToString())) & 0xff);
                            Send_buf[44] = Convert.ToByte(Convert.ToUInt16(CH13A11_B14.Value.ToString()) >> 8);
                            Send_buf[45] = Convert.ToByte((Convert.ToUInt16(CH13A11_B14.Value.ToString())) & 0xff);
                            Send_buf[46] = Convert.ToByte(Convert.ToUInt16(CH13A11_B15.Value.ToString()) >> 8);
                            Send_buf[47] = Convert.ToByte((Convert.ToUInt16(CH13A11_B15.Value.ToString())) & 0xff);
                            Send_buf[48] = Convert.ToByte(Convert.ToUInt16(CH13A11_B16.Value.ToString()) >> 8);
                            Send_buf[49] = Convert.ToByte((Convert.ToUInt16(CH13A11_B16.Value.ToString())) & 0xff);
                            Send_buf[50] = Convert.ToByte(Convert.ToUInt16(CH13A11_B17.Value.ToString()) >> 8);
                            Send_buf[51] = Convert.ToByte((Convert.ToUInt16(CH13A11_B17.Value.ToString())) & 0xff);
                            Send_buf[52] = Convert.ToByte(Convert.ToUInt16(CH13A11_B18.Value.ToString()) >> 8);
                            Send_buf[53] = Convert.ToByte((Convert.ToUInt16(CH13A11_B18.Value.ToString())) & 0xff);
                        }
                    }
                    break;
                //-----------------------------------------------------------------------
                case "CH13A11_GammaR_RED":
                    {
                        Send_buf[1] = 0x09;                             //读Gamma
                        Send_buf[3] = 0x01;
                    }
                    break;
                case "CH13A11_GammaR_GREEN":
                    {
                        Send_buf[1] = 0x09;                             //读Gamma
                        Send_buf[3] = 0x02;
                    }
                    break;
                case "CH13A11_GammaR_BLUE":
                    {

                        Send_buf[1] = 0x09;                             //读Gamma
                        Send_buf[3] = 0x03;
                    }
                    break;
            }
            CRCData.CalculateCrc16(Send_buf, out Send_buf[Setting.TempRecord.cmdLen - 2], out Send_buf[Setting.TempRecord.cmdLen - 1]);
            try
            {
                frmHelp.comPort.Write(Send_buf, 0, Setting.TempRecord.cmdLen);   //
            }
            catch
            {
                MessageBox.Show("串口有误，请检查", "错误");
            }
            frmHelp.T1.Enabled = false;
            frmHelp.T1.Interval = 2000;
            frmHelp.T1.Enabled = true;
        }


        private void Rbt_CH13A11_25points_CheckedChanged(object sender, EventArgs e)
        {
            CH13A11_R17.Enabled = true;
            CH13A11_R18.Enabled = true;
            CH13A11_R19.Enabled = true;
            CH13A11_R20.Enabled = true;
            CH13A11_R21.Enabled = true;
            CH13A11_R22.Enabled = true;
            CH13A11_R23.Enabled = true;
            CH13A11_R24.Enabled = true;

            CH13A11_G17.Enabled = true;
            CH13A11_G18.Enabled = true;
            CH13A11_G19.Enabled = true;
            CH13A11_G20.Enabled = true;
            CH13A11_G21.Enabled = true;
            CH13A11_G22.Enabled = true;
            CH13A11_G23.Enabled = true;
            CH13A11_G24.Enabled = true;

            CH13A11_B17.Enabled = true;
            CH13A11_B18.Enabled = true;
            CH13A11_B19.Enabled = true;
            CH13A11_B20.Enabled = true;
            CH13A11_B21.Enabled = true;
            CH13A11_B22.Enabled = true;
            CH13A11_B23.Enabled = true;
            CH13A11_B24.Enabled = true;

            listBox117.Items[0] = "R163"; listBox1.Items[0] = "G163"; listBox5.Items[0] = "B163";
            listBox117.Items[1] = "R179"; listBox1.Items[1] = "G179"; listBox5.Items[1] = "B179";
            listBox117.Items[2] = "R195"; listBox1.Items[2] = "G195"; listBox5.Items[2] = "B195";
            listBox117.Items[3] = "R211"; listBox1.Items[3] = "G211"; listBox5.Items[3] = "B211";
            listBox117.Items[4] = "R227"; listBox1.Items[4] = "G227"; listBox5.Items[4] = "B227";
            listBox117.Items[5] = "R243"; listBox1.Items[5] = "G243"; listBox5.Items[5] = "B243";
            listBox117.Items[6] = "R255"; listBox1.Items[6] = "G255"; listBox5.Items[6] = "B255";

            listBox118.Items[0] = "R51"; listBox2.Items[0] = "G51"; listBox6.Items[0] = "B51";
            listBox118.Items[1] = "R67"; listBox2.Items[1] = "G67"; listBox6.Items[1] = "B67";
            listBox118.Items[2] = "R83"; listBox2.Items[2] = "G83"; listBox6.Items[2] = "B83";
            listBox118.Items[3] = "R99"; listBox2.Items[3] = "G99"; listBox6.Items[3] = "B99";
            listBox118.Items[4] = "R115"; listBox2.Items[4] = "G115"; listBox6.Items[4] = "B115";
            listBox118.Items[5] = "R131"; listBox2.Items[5] = "G131"; listBox6.Items[5] = "B131";
            listBox118.Items[6] = "R147"; listBox2.Items[6] = "G147"; listBox6.Items[6] = "B147";

            listBox119.Items[0] = "R7"; listBox3.Items[0] = "G7"; listBox7.Items[0] = "B7";
            listBox119.Items[1] = "R11"; listBox3.Items[1] = "G11"; listBox7.Items[1] = "B11";
            listBox119.Items[2] = "R15"; listBox3.Items[2] = "G15"; listBox7.Items[2] = "B15";
            listBox119.Items[3] = "R19"; listBox3.Items[3] = "G19"; listBox7.Items[3] = "B19";
            listBox119.Items[4] = "R27"; listBox3.Items[4] = "G27"; listBox7.Items[4] = "B27";
            listBox119.Items[5] = "R35"; listBox3.Items[5] = "G35"; listBox7.Items[5] = "B35";
            listBox119.Items[6] = "R43"; listBox3.Items[6] = "G43"; listBox7.Items[6] = "B43";

            listBox121.Items[0] = "R0"; listBox4.Items[0] = "G0"; listBox8.Items[0] = "B0";
            listBox121.Items[1] = "R1"; listBox4.Items[1] = "G1"; listBox8.Items[1] = "B1";
            listBox121.Items[2] = "R3"; listBox4.Items[2] = "G3"; listBox8.Items[2] = "B3";
            listBox121.Items[3] = "R5"; listBox4.Items[3] = "G5"; listBox8.Items[3] = "B5";

            CH13A11_Gamma_SetBox.Text = null;
            CH13A11_Gamma_SetBox.Text =
            "__GAMMA_SET(0)\r\n" +
            "TUNING_SPEC(25, 630, 0.305, 0.325, 2.2)\r\n" +
            "LXY_SPEC(255, 0.001, 0.001, 0.15)\r\n" +
            "LXY_SPEC(243, 0.001, 0.001, 0.15)\r\n" +
            "LXY_SPEC(227, 0.001, 0.001, 0.15)\r\n" +
            "LXY_SPEC(211, 0.001, 0.001, 0.15)\r\n" +
            "LXY_SPEC(195, 0.001, 0.001, 0.15)\r\n" +
            "LXY_SPEC(179, 0.001, 0.001, 0.15)\r\n" +
            "LXY_SPEC(163, 0.001, 0.001, 0.15)\r\n" +
            "LXY_SPEC(147, 0.001, 0.001, 0.15)\r\n" +
            "LXY_SPEC(131, 0.001, 0.001, 0.15)\r\n" +
            "LXY_SPEC(115, 0.001, 0.001, 0.15)\r\n" +
            "LXY_SPEC(99, 0.001, 0.001, 0.15)\r\n" +
            "LXY_SPEC(83, 0.001, 0.001, 0.15)\r\n" +
            "LXY_SPEC(67, 0.001, 0.001, 0.15)\r\n" +
            "LXY_SPEC(51, 0.001, 0.001, 0.15)\r\n" +
            "LXY_SPEC(43, 0.001, 0.001, 0.15)\r\n" +
            "LXY_SPEC(35, 0.001, 0.001, 0.15)\r\n" +
            "LXY_SPEC(27, 0.001, 0.001, 0.15)\r\n" +
            "LXY_SPEC(19, 0.001, 0.001, 0.15)\r\n" +
            "LXY_SPEC(15, 0.001, 0.001, 0.15)\r\n" +
            "LXY_SPEC(11, 0.001, 0.001, 0.15)\r\n" +
            "LXY_SPEC(7, 0.001, 0.001, 0.15)\r\n" +
            "LXY_SPEC(5, 0.001, 0.001, 0.15)\r\n" +
            "LXY_SPEC(3, 0.001, 0.001, 0.15)\r\n" +
            "LXY_SPEC(1, 0.001, 0.001, 0.15)\r\n" +
            "LXY_SPEC(0, 0.001, 0.001, 0.15)\r\n" +
            "__GAMMA_TUNING \r\n" +
            "SAVE";
        }


        private void Rbt_CH13A11_34points_CheckedChanged(object sender, EventArgs e)
        {//121 119 118 117	R
         ////4  3  2  1 G
         //8 7 6 5 B
            CH13A11_R16.Enabled = true;
            CH13A11_R17.Enabled = true;
            CH13A11_R18.Enabled = true;
            CH13A11_R19.Enabled = true;
            CH13A11_R20.Enabled = true;
            CH13A11_R21.Enabled = true;
            CH13A11_R22.Enabled = true;
            CH13A11_R23.Enabled = true;
            CH13A11_R24.Enabled = true;
            CH13A11_R25.Enabled = true;
            CH13A11_R26.Enabled = true;
            CH13A11_R27.Enabled = true;
            CH13A11_R28.Enabled = true;
            CH13A11_R29.Enabled = true;
            CH13A11_R30.Enabled = true;
            CH13A11_R31.Enabled = true;
            CH13A11_R32.Enabled = true;
            CH13A11_R33.Enabled = true;

            CH13A11_G16.Enabled = true;
            CH13A11_G17.Enabled = true;
            CH13A11_G18.Enabled = true;
            CH13A11_G19.Enabled = true;
            CH13A11_G20.Enabled = true;
            CH13A11_G21.Enabled = true;
            CH13A11_G22.Enabled = true;
            CH13A11_G23.Enabled = true;
            CH13A11_G24.Enabled = true;
            CH13A11_G25.Enabled = true;
            CH13A11_G26.Enabled = true;
            CH13A11_G27.Enabled = true;
            CH13A11_G28.Enabled = true;
            CH13A11_G29.Enabled = true;
            CH13A11_G30.Enabled = true;
            CH13A11_G31.Enabled = true;
            CH13A11_G32.Enabled = true;
            CH13A11_G33.Enabled = true;

            CH13A11_B16.Enabled = true;
            CH13A11_B17.Enabled = true;
            CH13A11_B18.Enabled = true;
            CH13A11_B19.Enabled = true;
            CH13A11_B20.Enabled = true;
            CH13A11_B21.Enabled = true;
            CH13A11_B22.Enabled = true;
            CH13A11_B23.Enabled = true;
            CH13A11_B24.Enabled = true;
            CH13A11_B25.Enabled = true;
            CH13A11_B26.Enabled = true;
            CH13A11_B27.Enabled = true;
            CH13A11_B28.Enabled = true;
            CH13A11_B29.Enabled = true;
            CH13A11_B30.Enabled = true;
            CH13A11_B31.Enabled = true;
            CH13A11_B32.Enabled = true;
            CH13A11_B33.Enabled = true;


            listBox117.Items[0] = "R220"; listBox1.Items[0] = "G220"; listBox5.Items[0] = "B220";
            listBox117.Items[1] = "R228"; listBox1.Items[1] = "G228"; listBox5.Items[1] = "B228";
            listBox117.Items[2] = "R236"; listBox1.Items[2] = "G236"; listBox5.Items[2] = "B236";
            listBox117.Items[3] = "R244"; listBox1.Items[3] = "G244"; listBox5.Items[3] = "B244";
            listBox117.Items[4] = "R248"; listBox1.Items[4] = "G248"; listBox5.Items[4] = "B248";
            listBox117.Items[5] = "R250"; listBox1.Items[5] = "G250"; listBox5.Items[5] = "B250";
            listBox117.Items[6] = "R252"; listBox1.Items[6] = "G252"; listBox5.Items[6] = "B252";
            listBox117.Items[7] = "R254"; listBox1.Items[7] = "G254"; listBox5.Items[7] = "B254";
            listBox117.Items[8] = "R255"; listBox1.Items[8] = "G255"; listBox5.Items[8] = "B255";

            listBox118.Items[0] = "R124"; listBox2.Items[0] = "G124"; listBox6.Items[0] = "B124";
            listBox118.Items[1] = "R132"; listBox2.Items[1] = "G132"; listBox6.Items[1] = "B132";
            listBox118.Items[2] = "R148"; listBox2.Items[2] = "G148"; listBox6.Items[2] = "B148";
            listBox118.Items[3] = "R164"; listBox2.Items[3] = "G164"; listBox6.Items[3] = "B164";
            listBox118.Items[4] = "R180"; listBox2.Items[4] = "G180"; listBox6.Items[4] = "B180";
            listBox118.Items[5] = "R188"; listBox2.Items[5] = "G188"; listBox6.Items[5] = "B188";
            listBox118.Items[6] = "R196"; listBox2.Items[6] = "G196"; listBox6.Items[6] = "B196";
            listBox118.Items[7] = "R204"; listBox2.Items[7] = "G204"; listBox6.Items[7] = "B204";
            listBox118.Items[8] = "R212"; listBox2.Items[8] = "G212"; listBox6.Items[8] = "B212";

            listBox119.Items[0] = "R28"; listBox3.Items[0] = "G28"; listBox7.Items[0] = "B28";
            listBox119.Items[1] = "R36"; listBox3.Items[1] = "G36"; listBox7.Items[1] = "B36";
            listBox119.Items[2] = "R44"; listBox3.Items[2] = "G44"; listBox7.Items[2] = "B44";
            listBox119.Items[3] = "R52"; listBox3.Items[3] = "G52"; listBox7.Items[3] = "B52";
            listBox119.Items[4] = "R68"; listBox3.Items[4] = "G68"; listBox7.Items[4] = "B68";
            listBox119.Items[5] = "R84"; listBox3.Items[5] = "G84"; listBox7.Items[5] = "B84";
            listBox119.Items[6] = "R100"; listBox3.Items[6] = "G100"; listBox7.Items[6] = "B100";
            listBox119.Items[7] = "R116"; listBox3.Items[7] = "G116"; listBox7.Items[7] = "B116";

            listBox121.Items[0] = "R0"; listBox4.Items[0] = "G0"; listBox8.Items[0] = "B0";
            listBox121.Items[1] = "R1"; listBox4.Items[1] = "G1"; listBox8.Items[1] = "B1";
            listBox121.Items[2] = "R3"; listBox4.Items[2] = "G3"; listBox8.Items[2] = "B3";
            listBox121.Items[3] = "R4"; listBox4.Items[3] = "G4"; listBox8.Items[3] = "B4";
            listBox121.Items[4] = "R8"; listBox4.Items[4] = "G8"; listBox8.Items[4] = "B8";
            listBox121.Items[5] = "R12"; listBox4.Items[5] = "G12"; listBox8.Items[5] = "B12";
            listBox121.Items[6] = "R16"; listBox4.Items[6] = "G16"; listBox8.Items[6] = "B16";
            listBox121.Items[7] = "R20"; listBox4.Items[7] = "G20"; listBox8.Items[7] = "B20";


            CH13A11_Gamma_SetBox.Text = null;
            CH13A11_Gamma_SetBox.Text =
            "__GAMMA_SET(0)\r\n" +
            "TUNING_SPEC(34, 600, 0.305, 0.325, 2.1)\r\n" +
            "LXY_SPEC(255, 0.001, 0.001, 0.15)\r\n" +
            "LXY_SPEC(254, 0.001, 0.001, 0.15)\r\n" +
            "LXY_SPEC(252, 0.001, 0.001, 0.15)\r\n" +
            "LXY_SPEC(250, 0.001, 0.001, 0.15)\r\n" +
            "LXY_SPEC(248, 0.001, 0.001, 0.15)\r\n" +
            "LXY_SPEC(244, 0.001, 0.001, 0.15)\r\n" +
            "LXY_SPEC(236, 0.001, 0.001, 0.15)\r\n" +
            "LXY_SPEC(228, 0.001, 0.001, 0.15)\r\n" +
            "LXY_SPEC(220, 0.001, 0.001, 0.15)\r\n" +
            "LXY_SPEC(212, 0.001, 0.001, 0.15)\r\n" +
            "LXY_SPEC(204, 0.001, 0.001, 0.15)\r\n" +
            "LXY_SPEC(196, 0.001, 0.001, 0.15)\r\n" +
            "LXY_SPEC(188, 0.001, 0.001, 0.15)\r\n" +
            "LXY_SPEC(180, 0.001, 0.001, 0.15)\r\n" +
            "LXY_SPEC(164, 0.001, 0.001, 0.15)\r\n" +
            "LXY_SPEC(148, 0.001, 0.001, 0.15)\r\n" +
            "LXY_SPEC(132, 0.001, 0.001, 0.15)\r\n" +
            "LXY_SPEC(124, 0.001, 0.001, 0.15)\r\n" +
            "LXY_SPEC(116, 0.001, 0.001, 0.15)\r\n" +
            "LXY_SPEC(100, 0.001, 0.001, 0.15)\r\n" +
            "LXY_SPEC(84, 0.001, 0.001, 0.15)\r\n" +
            "LXY_SPEC(68, 0.001, 0.001, 0.15)\r\n" +
            "LXY_SPEC(52, 0.001, 0.001, 0.15)\r\n" +
            "LXY_SPEC(44, 0.001, 0.001, 0.15)\r\n" +
            "LXY_SPEC(36, 0.001, 0.001, 0.15)\r\n" +
            "LXY_SPEC(28, 0.001, 0.001, 0.15)\r\n" +
            "LXY_SPEC(20, 0.001, 0.001, 0.15)\r\n" +
            "LXY_SPEC(16, 0.001, 0.001, 0.15)\r\n" +
            "LXY_SPEC(12, 0.001, 0.001, 0.15)\r\n" +
            "LXY_SPEC(8, 0.001, 0.001, 0.15)\r\n" +
            "LXY_SPEC(4, 0.001, 0.001, 0.15)\r\n" +
            "LXY_SPEC(3, 0.001, 0.001, 0.15)\r\n" +
            "LXY_SPEC(1, 0.001, 0.001, 0.15)\r\n" +
            "LXY_SPEC(0, 0.001, 0.001, 0.15)\r\n" +
            "__GAMMA_TUNING \r\n" +
            "SAVE";
        }
        private void Rbt_CH13A11_20points_CheckedChanged(object sender, EventArgs e)
        {//121 119 118 117	R
         ////4  3  2  1 G
         //8 7 6 5 B

            CH13A11_R17.Enabled = true;
            CH13A11_R18.Enabled = true;
            CH13A11_R19.Enabled = true;
            CH13A11_R20.Enabled = false;
            CH13A11_R21.Enabled = false;
            CH13A11_R22.Enabled = false;
            CH13A11_R23.Enabled = false;
            CH13A11_R24.Enabled = false;

            CH13A11_G17.Enabled = true;
            CH13A11_G18.Enabled = true;
            CH13A11_G19.Enabled = true;
            CH13A11_G20.Enabled = false;
            CH13A11_G21.Enabled = false;
            CH13A11_G22.Enabled = false;
            CH13A11_G23.Enabled = false;
            CH13A11_G24.Enabled = false;


            CH13A11_B17.Enabled = true;
            CH13A11_B18.Enabled = true;
            CH13A11_B19.Enabled = true;
            CH13A11_B20.Enabled = false;
            CH13A11_B21.Enabled = false;
            CH13A11_B22.Enabled = false;
            CH13A11_B23.Enabled = false;
            CH13A11_B24.Enabled = false;

            listBox117.Items[0] = "R240"; listBox1.Items[0] = "G240"; listBox5.Items[0] = "B240";
            listBox117.Items[1] = "R255"; listBox1.Items[1] = "G255"; listBox5.Items[1] = "B255";
            listBox117.Items[2] = "XXXX"; listBox1.Items[2] = "XXXX"; listBox5.Items[2] = "XXXX";
            listBox117.Items[3] = "XXXX"; listBox1.Items[3] = "XXXX"; listBox5.Items[3] = "XXXX";
            listBox117.Items[4] = "XXXX"; listBox1.Items[4] = "XXXX"; listBox5.Items[4] = "XXXX";
            listBox117.Items[5] = "XXXX"; listBox1.Items[5] = "XXXX"; listBox5.Items[5] = "XXXX";
            listBox117.Items[6] = "XXXX"; listBox1.Items[6] = "XXXX"; listBox5.Items[6] = "XXXX";


            listBox118.Items[0] = "R97"; listBox2.Items[0] = "G97"; listBox6.Items[0] = "B97";
            listBox118.Items[1] = "R112"; listBox2.Items[1] = "G112"; listBox6.Items[1] = "B112";
            listBox118.Items[2] = "R146"; listBox2.Items[2] = "G146"; listBox6.Items[2] = "B146";
            listBox118.Items[3] = "R161"; listBox2.Items[3] = "G161"; listBox6.Items[3] = "B161";
            listBox118.Items[4] = "R176"; listBox2.Items[4] = "G176"; listBox6.Items[4] = "B176";
            listBox118.Items[5] = "R210"; listBox2.Items[5] = "G210"; listBox6.Items[5] = "B210";
            listBox118.Items[6] = "R225"; listBox2.Items[6] = "G225"; listBox6.Items[6] = "B225";

            listBox119.Items[0] = "R15"; listBox3.Items[0] = "G15"; listBox7.Items[0] = "B15";
            listBox119.Items[1] = "R23"; listBox3.Items[1] = "G23"; listBox7.Items[1] = "B23";
            listBox119.Items[2] = "R31"; listBox3.Items[2] = "G31"; listBox7.Items[2] = "B31";
            listBox119.Items[3] = "R35"; listBox3.Items[3] = "G35"; listBox7.Items[3] = "B35";
            listBox119.Items[4] = "R47"; listBox3.Items[4] = "G47"; listBox7.Items[4] = "B47";
            listBox119.Items[5] = "R63"; listBox3.Items[5] = "G63"; listBox7.Items[5] = "B63";
            listBox119.Items[6] = "R82"; listBox3.Items[6] = "G82"; listBox7.Items[6] = "B82";

            listBox121.Items[0] = "R0"; listBox4.Items[0] = "G0"; listBox8.Items[0] = "B0";
            listBox121.Items[1] = "R1"; listBox4.Items[1] = "G1"; listBox8.Items[1] = "B1";
            listBox121.Items[2] = "R3"; listBox4.Items[2] = "G3"; listBox8.Items[2] = "B3";
            listBox121.Items[3] = "R7"; listBox4.Items[3] = "G7"; listBox8.Items[3] = "B7";

            CH13A11_Gamma_SetBox.Text = null;
            CH13A11_Gamma_SetBox.Text =
            "__GAMMA_SET(0)\r\n" +
            "TUNING_SPEC(20, 630, 0.305, 0.325, 2.2)\r\n" +
            "LXY_SPEC(255, 0.001, 0.001, 0.01)\r\n" +
            "LXY_SPEC(240, 0.001, 0.001, 0.01)\r\n" +
            "LXY_SPEC(225, 0.001, 0.001, 0.01)\r\n" +
            "LXY_SPEC(210, 0.001, 0.001, 0.01)\r\n" +
            "LXY_SPEC(176, 0.001, 0.001, 0.01)\r\n" +
            "LXY_SPEC(161, 0.001, 0.001, 0.01)\r\n" +
            "LXY_SPEC(146, 0.001, 0.001, 0.01)\r\n" +
            "LXY_SPEC(112, 0.001, 0.001, 0.01)\r\n" +
            "LXY_SPEC(97, 0.001, 0.001, 0.01)\r\n" +
            "LXY_SPEC(82, 0.001, 0.001, 0.01)\r\n" +
            "LXY_SPEC(63, 0.001, 0.001, 0.01)\r\n" +
            "LXY_SPEC(47, 0.001, 0.001, 0.1)\r\n" +
            "LXY_SPEC(35, 0.001, 0.001, 0.1)\r\n" +
            "LXY_SPEC(31, 0.001, 0.001, 0.1)\r\n" +
            "LXY_SPEC(23, 0.001, 0.001, 0.1)\r\n" +
            "LXY_SPEC(15, 0.001, 0.001, 0.1)\r\n" +
            "LXY_SPEC(7, 0.001, 0.001, 0.1)\r\n" +
            "LXY_SPEC(3, 0.001, 0.001, 0.1)\r\n" +
            "LXY_SPEC(1, 0.001, 0.001, 0.1)\r\n" +
            "LXY_SPEC(0, 0.001, 0.001, 0.1)\r\n" +
            "__GAMMA_TUNING \r\n" +
            "SAVE";
        }
        private void Rbt_CH13A11_17points_CheckedChanged(object sender, EventArgs e)
        {
            CH13A11_R16.Enabled = false;
            CH13A11_R17.Enabled = false;
            CH13A11_R18.Enabled = false;
            CH13A11_R19.Enabled = false;
            CH13A11_R20.Enabled = false;
            CH13A11_R21.Enabled = false;
            CH13A11_R22.Enabled = false;
            CH13A11_R23.Enabled = false;
            CH13A11_R24.Enabled = false;

            CH13A11_G16.Enabled = false;
            CH13A11_G17.Enabled = false;
            CH13A11_G18.Enabled = false;
            CH13A11_G19.Enabled = false;
            CH13A11_G20.Enabled = false;
            CH13A11_G21.Enabled = false;
            CH13A11_G22.Enabled = false;
            CH13A11_G23.Enabled = false;
            CH13A11_G24.Enabled = false;

            CH13A11_B16.Enabled = false;
            CH13A11_B17.Enabled = false;
            CH13A11_B18.Enabled = false;
            CH13A11_B19.Enabled = false;
            CH13A11_B20.Enabled = false;
            CH13A11_B21.Enabled = false;
            CH13A11_B22.Enabled = false;
            CH13A11_B23.Enabled = false;
            CH13A11_B24.Enabled = false;

            listBox117.Items[0] = "XXXX"; listBox1.Items[0] = "XXXX"; listBox5.Items[0] = "XXXX";
            listBox117.Items[1] = "XXXX"; listBox1.Items[1] = "XXXX"; listBox5.Items[1] = "XXXX";
            listBox117.Items[2] = "XXXX"; listBox1.Items[2] = "XXXX"; listBox5.Items[2] = "XXXX";
            listBox117.Items[3] = "XXXX"; listBox1.Items[3] = "XXXX"; listBox5.Items[3] = "XXXX";
            listBox117.Items[4] = "XXXX"; listBox1.Items[4] = "XXXX"; listBox5.Items[4] = "XXXX";
            listBox117.Items[5] = "XXXX"; listBox1.Items[5] = "XXXX"; listBox5.Items[5] = "XXXX";
            listBox117.Items[6] = "XXXX"; listBox1.Items[6] = "XXXX"; listBox5.Items[6] = "XXXX";


            listBox118.Items[0] = "R111"; listBox2.Items[0] = "G111"; listBox6.Items[0] = "B111";
            listBox118.Items[1] = "R143"; listBox2.Items[1] = "R143"; listBox6.Items[1] = "B143";
            listBox118.Items[2] = "R175"; listBox2.Items[2] = "R175"; listBox6.Items[2] = "B175";
            listBox118.Items[3] = "R207"; listBox2.Items[3] = "R207"; listBox6.Items[3] = "B207";
            listBox118.Items[4] = "R239"; listBox2.Items[4] = "R239"; listBox6.Items[4] = "B239";
            listBox118.Items[5] = "R255"; listBox2.Items[5] = "R255"; listBox6.Items[5] = "B255";
            listBox118.Items[6] = "XXXX"; listBox2.Items[6] = "XXXX"; listBox6.Items[6] = "XXXX";

            listBox119.Items[0] = "R15"; listBox3.Items[0] = "G15"; listBox7.Items[0] = "B15";
            listBox119.Items[1] = "R23"; listBox3.Items[1] = "G23"; listBox7.Items[1] = "B23";
            listBox119.Items[2] = "R31"; listBox3.Items[2] = "G31"; listBox7.Items[2] = "B31";
            listBox119.Items[3] = "R35"; listBox3.Items[3] = "G35"; listBox7.Items[3] = "B35";
            listBox119.Items[4] = "R47"; listBox3.Items[4] = "G47"; listBox7.Items[4] = "B47";
            listBox119.Items[5] = "R63"; listBox3.Items[5] = "G63"; listBox7.Items[5] = "B63";
            listBox119.Items[6] = "R79"; listBox3.Items[6] = "G79"; listBox7.Items[6] = "B79";

            listBox121.Items[0] = "R0"; listBox4.Items[0] = "G0"; listBox8.Items[0] = "B0";
            listBox121.Items[1] = "R1"; listBox4.Items[1] = "G1"; listBox8.Items[1] = "B1";
            listBox121.Items[2] = "R3"; listBox4.Items[2] = "G3"; listBox8.Items[2] = "B3";
            listBox121.Items[3] = "R7"; listBox4.Items[3] = "G7"; listBox8.Items[3] = "B7";

            CH13A11_Gamma_SetBox.Text = null;
            CH13A11_Gamma_SetBox.Text =
            "__GAMMA_SET(0)\r\n" +
            "TUNING_SPEC(17, 630, 0.305, 0.325, 2.2)\r\n" +
            "LXY_SPEC(255, 0.001, 0.001, 0.01)\r\n" +
            "LXY_SPEC(239, 0.001, 0.001, 0.01)\r\n" +
            "LXY_SPEC(207, 0.001, 0.001, 0.01)\r\n" +
            "LXY_SPEC(175, 0.001, 0.001, 0.01)\r\n" +
            "LXY_SPEC(143, 0.001, 0.001, 0.01)\r\n" +
            "LXY_SPEC(111, 0.001, 0.001, 0.01)\r\n" +
            "LXY_SPEC(79, 0.001, 0.001, 0.01)\r\n" +
            "LXY_SPEC(63, 0.001, 0.001, 0.01)\r\n" +
            "LXY_SPEC(47, 0.001, 0.001, 0.1)\r\n" +
            "LXY_SPEC(35, 0.001, 0.001, 0.1)\r\n" +
            "LXY_SPEC(31, 0.001, 0.001, 0.1)\r\n" +
            "LXY_SPEC(23, 0.001, 0.001, 0.1)\r\n" +
            "LXY_SPEC(15, 0.001, 0.001, 0.1)\r\n" +
            "LXY_SPEC(7, 0.001, 0.001, 0.1)\r\n" +
            "LXY_SPEC(3, 0.001, 0.001, 0.1)\r\n" +
            "LXY_SPEC(1, 0.001, 0.001, 0.1)\r\n" +
            "LXY_SPEC(0, 0.001, 0.001, 0.1)\r\n" +
            "__GAMMA_TUNING \r\n" +
            "SAVE";
        }
        private void Rbt_CH13A11_15points_CheckedChanged(object sender, EventArgs e)
        {
            CH13A11_R14.Enabled = false;
            CH13A11_R15.Enabled = false;
            CH13A11_R16.Enabled = false;
            CH13A11_R17.Enabled = false;
            CH13A11_R18.Enabled = false;
            CH13A11_R19.Enabled = false;
            CH13A11_R20.Enabled = false;
            CH13A11_R21.Enabled = false;
            CH13A11_R22.Enabled = false;
            CH13A11_R23.Enabled = false;
            CH13A11_R24.Enabled = false;

            CH13A11_G14.Enabled = false;
            CH13A11_G15.Enabled = false;
            CH13A11_G16.Enabled = false;
            CH13A11_G17.Enabled = false;
            CH13A11_G18.Enabled = false;
            CH13A11_G19.Enabled = false;
            CH13A11_G20.Enabled = false;
            CH13A11_G21.Enabled = false;
            CH13A11_G22.Enabled = false;
            CH13A11_G23.Enabled = false;
            CH13A11_G24.Enabled = false;

            CH13A11_B14.Enabled = false;
            CH13A11_B15.Enabled = false;
            CH13A11_B16.Enabled = false;
            CH13A11_B17.Enabled = false;
            CH13A11_B18.Enabled = false;
            CH13A11_B19.Enabled = false;
            CH13A11_B20.Enabled = false;
            CH13A11_B21.Enabled = false;
            CH13A11_B22.Enabled = false;
            CH13A11_B23.Enabled = false;
            CH13A11_B24.Enabled = false;

            listBox117.Items[0] = "XXXX"; listBox1.Items[0] = "XXXX"; listBox5.Items[0] = "XXXX";
            listBox117.Items[1] = "XXXX"; listBox1.Items[1] = "XXXX"; listBox5.Items[1] = "XXXX";
            listBox117.Items[2] = "XXXX"; listBox1.Items[2] = "XXXX"; listBox5.Items[2] = "XXXX";
            listBox117.Items[3] = "XXXX"; listBox1.Items[3] = "XXXX"; listBox5.Items[3] = "XXXX";
            listBox117.Items[4] = "XXXX"; listBox1.Items[4] = "XXXX"; listBox5.Items[4] = "XXXX";
            listBox117.Items[5] = "XXXX"; listBox1.Items[5] = "XXXX"; listBox5.Items[5] = "XXXX";
            listBox117.Items[6] = "XXXX"; listBox1.Items[6] = "XXXX"; listBox5.Items[6] = "XXXX";


            listBox118.Items[0] = "R143"; listBox2.Items[0] = "G143"; listBox6.Items[0] = "B143";
            listBox118.Items[1] = "R207"; listBox2.Items[1] = "R207"; listBox6.Items[1] = "B207";
            listBox118.Items[2] = "R239"; listBox2.Items[2] = "R239"; listBox6.Items[2] = "B239";
            listBox118.Items[3] = "R255"; listBox2.Items[3] = "G255"; listBox6.Items[3] = "B255";
            listBox118.Items[4] = "XXXX"; listBox2.Items[4] = "XXXX"; listBox6.Items[4] = "XXXX";
            listBox118.Items[5] = "XXXX"; listBox2.Items[5] = "XXXX"; listBox6.Items[5] = "XXXX";
            listBox118.Items[6] = "XXXX"; listBox2.Items[6] = "XXXX"; listBox6.Items[6] = "XXXX";

            listBox119.Items[0] = "R15"; listBox3.Items[0] = "G15"; listBox7.Items[0] = "B15";
            listBox119.Items[1] = "R23"; listBox3.Items[1] = "G23"; listBox7.Items[1] = "B23";
            listBox119.Items[2] = "R31"; listBox3.Items[2] = "G31"; listBox7.Items[2] = "B31";
            listBox119.Items[3] = "R47"; listBox3.Items[3] = "G47"; listBox7.Items[3] = "B47";
            listBox119.Items[4] = "R63"; listBox3.Items[4] = "G63"; listBox7.Items[4] = "B63";
            listBox119.Items[5] = "R79"; listBox3.Items[5] = "G79"; listBox7.Items[5] = "B79";
            listBox119.Items[6] = "R111"; listBox3.Items[6] = "G111"; listBox7.Items[6] = "B111";

            listBox121.Items[0] = "R0"; listBox4.Items[0] = "G0"; listBox8.Items[0] = "B0";
            listBox121.Items[1] = "R1"; listBox4.Items[1] = "G1"; listBox8.Items[1] = "B1";
            listBox121.Items[2] = "R3"; listBox4.Items[2] = "G3"; listBox8.Items[2] = "B3";
            listBox121.Items[3] = "R7"; listBox4.Items[3] = "G7"; listBox8.Items[3] = "B7";

            CH13A11_Gamma_SetBox.Text = null;
            CH13A11_Gamma_SetBox.Text =
            "__GAMMA_SET(0)\r\n" +
            "TUNING_SPEC(15, 630, 0.305, 0.325, 2.2)\r\n" +
            "LXY_SPEC(255, 0.001, 0.001, 0.01)\r\n" +
            "LXY_SPEC(239, 0.001, 0.001, 0.01)\r\n" +
            "LXY_SPEC(207, 0.001, 0.001, 0.01)\r\n" +
            "LXY_SPEC(143, 0.001, 0.001, 0.01)\r\n" +
            "LXY_SPEC(111, 0.001, 0.001, 0.01)\r\n" +
            "LXY_SPEC(79, 0.001, 0.001, 0.01)\r\n" +
            "LXY_SPEC(63, 0.001, 0.001, 0.01)\r\n" +
            "LXY_SPEC(47, 0.001, 0.001, 0.1)\r\n" +
            "LXY_SPEC(31, 0.001, 0.001, 0.1)\r\n" +
            "LXY_SPEC(23, 0.001, 0.001, 0.1)\r\n" +
            "LXY_SPEC(15, 0.001, 0.001, 0.1)\r\n" +
            "LXY_SPEC(7, 0.001, 0.001, 0.1)\r\n" +
            "LXY_SPEC(3, 0.001, 0.001, 0.1)\r\n" +
            "LXY_SPEC(1, 0.001, 0.001, 0.1)\r\n" +
            "LXY_SPEC(0, 0.001, 0.001, 0.1)\r\n" +
            "__GAMMA_TUNING \r\n" +
            "SAVE";
        }

        private void rbt_CH13A11_19points_CheckedChanged(object sender, EventArgs e)
        {

            CH13A11_R13.Enabled = true;
            CH13A11_R14.Enabled = true;
            CH13A11_R15.Enabled = true;
            CH13A11_R16.Enabled = true;
            CH13A11_R17.Enabled = true;
            CH13A11_R18.Enabled = false;
            CH13A11_R19.Enabled = false;
            CH13A11_R20.Enabled = false;
            CH13A11_R21.Enabled = false;
            CH13A11_R22.Enabled = false;
            CH13A11_R23.Enabled = false;
            CH13A11_R24.Enabled = false;


            CH13A11_G13.Enabled = true;
            CH13A11_G14.Enabled = true;
            CH13A11_G15.Enabled = true;
            CH13A11_G16.Enabled = true;
            CH13A11_G17.Enabled = true;
            CH13A11_G18.Enabled = false;
            CH13A11_G19.Enabled = false;
            CH13A11_G20.Enabled = false;
            CH13A11_G21.Enabled = false;
            CH13A11_G22.Enabled = false;
            CH13A11_G23.Enabled = false;
            CH13A11_G24.Enabled = false;

            CH13A11_B13.Enabled = true;
            CH13A11_B14.Enabled = true;
            CH13A11_B15.Enabled = true;
            CH13A11_B16.Enabled = true;
            CH13A11_B17.Enabled = true;
            CH13A11_B18.Enabled = false;
            CH13A11_B19.Enabled = false;
            CH13A11_B20.Enabled = false;
            CH13A11_B21.Enabled = false;
            CH13A11_B22.Enabled = false;
            CH13A11_B23.Enabled = false;
            CH13A11_B24.Enabled = false;

            listBox117.Items[0] = "R255"; listBox1.Items[0] = "G255"; listBox5.Items[0] = "B255";
            listBox117.Items[1] = "XXXX"; listBox1.Items[1] = "XXXX"; listBox5.Items[1] = "XXXX";
            listBox117.Items[2] = "XXXX"; listBox1.Items[2] = "XXXX"; listBox5.Items[2] = "XXXX";
            listBox117.Items[3] = "XXXX"; listBox1.Items[3] = "XXXX"; listBox5.Items[3] = "XXXX";
            listBox117.Items[4] = "XXXX"; listBox1.Items[4] = "XXXX"; listBox5.Items[4] = "XXXX";
            listBox117.Items[5] = "XXXX"; listBox1.Items[5] = "XXXX"; listBox5.Items[5] = "XXXX";
            listBox117.Items[6] = "XXXX"; listBox1.Items[6] = "XXXX"; listBox5.Items[6] = "XXXX";


            listBox118.Items[0] = "R111"; listBox2.Items[0] = "G111"; listBox6.Items[0] = "B111";
            listBox118.Items[1] = "R143"; listBox2.Items[1] = "G143"; listBox6.Items[1] = "B143";
            listBox118.Items[2] = "R175"; listBox2.Items[2] = "G175"; listBox6.Items[2] = "B175";
            listBox118.Items[3] = "R200"; listBox2.Items[3] = "G200"; listBox6.Items[3] = "B200";
            listBox118.Items[4] = "R207"; listBox2.Items[4] = "G207"; listBox6.Items[4] = "B207";
            listBox118.Items[5] = "R232"; listBox2.Items[5] = "G232"; listBox6.Items[5] = "B232";
            listBox118.Items[6] = "R239"; listBox2.Items[6] = "G239"; listBox6.Items[6] = "B239";

            listBox119.Items[0] = "R15"; listBox3.Items[0] = "G15"; listBox7.Items[0] = "B15";
            listBox119.Items[1] = "R23"; listBox3.Items[1] = "G23"; listBox7.Items[1] = "B23";
            listBox119.Items[2] = "R31"; listBox3.Items[2] = "G31"; listBox7.Items[2] = "B31";
            listBox119.Items[3] = "R35"; listBox3.Items[3] = "G35"; listBox7.Items[3] = "B35";
            listBox119.Items[4] = "R47"; listBox3.Items[4] = "G47"; listBox7.Items[4] = "B47";
            listBox119.Items[5] = "R63"; listBox3.Items[5] = "G63"; listBox7.Items[5] = "B63";
            listBox119.Items[6] = "R79"; listBox3.Items[6] = "G79"; listBox7.Items[6] = "B79";

            listBox121.Items[0] = "R0"; listBox4.Items[0] = "G0"; listBox8.Items[0] = "B0";
            listBox121.Items[1] = "R1"; listBox4.Items[1] = "G1"; listBox8.Items[1] = "B1";
            listBox121.Items[2] = "R3"; listBox4.Items[2] = "G3"; listBox8.Items[2] = "B3";
            listBox121.Items[3] = "R7"; listBox4.Items[3] = "G7"; listBox8.Items[3] = "B7";

            CH13A11_Gamma_SetBox.Text = null;
            CH13A11_Gamma_SetBox.Text =
            "__GAMMA_SET(0)\r\n" +
            "TUNING_SPEC(19, 630, 0.305, 0.325, 2.2)\r\n" +
            "LXY_SPEC(255, 0.001, 0.001, 0.01)\r\n" +
            "LXY_SPEC(239, 0.001, 0.001, 0.01)\r\n" +
            "LXY_SPEC(232, 0.001, 0.001, 0.01)\r\n" +
            "LXY_SPEC(207, 0.001, 0.001, 0.01)\r\n" +
            "LXY_SPEC(200, 0.001, 0.001, 0.01)\r\n" +
            "LXY_SPEC(175, 0.001, 0.001, 0.01)\r\n" +
            "LXY_SPEC(143, 0.001, 0.001, 0.01)\r\n" +
            "LXY_SPEC(111, 0.001, 0.001, 0.01)\r\n" +
            "LXY_SPEC(79, 0.001, 0.001, 0.01)\r\n" +
            "LXY_SPEC(63, 0.001, 0.001, 0.01)\r\n" +
            "LXY_SPEC(47, 0.001, 0.001, 0.1)\r\n" +
            "LXY_SPEC(35, 0.001, 0.001, 0.1)\r\n" +
            "LXY_SPEC(31, 0.001, 0.001, 0.1)\r\n" +
            "LXY_SPEC(23, 0.001, 0.001, 0.1)\r\n" +
            "LXY_SPEC(15, 0.001, 0.001, 0.1)\r\n" +
            "LXY_SPEC(7, 0.001, 0.001, 0.1)\r\n" +
            "LXY_SPEC(3, 0.001, 0.001, 0.1)\r\n" +
            "LXY_SPEC(1, 0.001, 0.001, 0.1)\r\n" +
            "LXY_SPEC(0, 0.001, 0.001, 0.1)\r\n" +
            "__GAMMA_TUNING \r\n" +
            "SAVE";
        }

        private void Send_Cmd_Demuura_Click(object sender, EventArgs e)
        {
            Button btn = (Button)sender;
            bool Send_en = true;
            switch (btn.Name)
            {
                case "btnSend_1": //1.Flash ID
                    {
                        frmHelp.Generate_textBox.Text = btnSend_Text1.Text;
                        frmHelp.Generate_File_Click(frmHelp.Generate_File_Run, e);
                        Send_en = false;
                    }
                    break;
                case "btnSend_2"://2.Check Flash 
                    {
                        frmHelp.Generate_textBox.Text = btnSend_Text2.Text;
                        frmHelp.Generate_File_Click(frmHelp.Generate_File_Run, e);
                        Send_en = false;
                        //frmHelp.txtProcessDrivercode(btnSend_Text2.Text, out string txtbaseClearOriginal, out string txtMCleatOriginal);
                    }
                    break;
                case "btnSend_3"://3.Flash Program
                    {
                        frmHelp.Generate_textBox.Text = btnSend_Text3.Text;
                        frmHelp.Generate_File_Click(frmHelp.Generate_File_Run, e);
                        Send_en = false;
                    }
                    break;
                case "btnSend_4"://4.Check CRC
                    {
                        frmHelp.Generate_textBox.Text = btnSend_Text4.Text;
                        frmHelp.Generate_File_Click(frmHelp.Generate_File_Run, e);
                        Send_en = false;
                    }
                    break;
                case "btnSend_5"://Demura ON
                    {
                        frmHelp.Generate_textBox.Text = btnSend_Text5.Text;
                        frmHelp.Generate_File_Click(frmHelp.Generate_File_Run, e);
                        Send_en = false;
                    }
                    break;
                case "btnSend_6"://Demura OFF
                    {
                        frmHelp.Generate_textBox.Text = btnSend_Text6.Text;
                        frmHelp.Generate_File_Click(frmHelp.Generate_File_Run, e);
                        Send_en = false;
                    }
                    break;
                case "btnSend_7"://Demura OFF
                    {
                        frmHelp.Generate_textBox.Text = btnSend_Text7.Text;
                        frmHelp.Generate_File_Click(frmHelp.Generate_File_Run, e);
                        Send_en = false;
                    }
                    break;
                    /*case "button_SD5306_1"://SD5306 Flash Program
                        {
                            frmHelp.txtProcessDrivercode(btnSend_SD5306_1.Text, out string txtbaseClearOriginal, out string txtMCleatOriginal);
                        }
                        break;
                    case "button_SD5306_2"://SD5306  Check CRC
                        {
                            frmHelp.Generate_textBox.Text = btnSend_SD5306_2.Text;
                            frmHelp.Generate_File_Click(frmHelp.Generate_File_Run, e);
                            Send_en = false;
                        }
                        break;*/

            }
            Setting.TempRecord.cmdLen = 6;
            if (Send_en == true)
            {
                if (rBt_LP_DCS_Long_Write.Checked | rBt_LP_DCS_Short_Write.Checked | rBt_LP_Gerneric_Long_Write.Checked | rBt_LP_Gerneric_Short_Write.Checked)
                {
                    frmHelp.SendCmd(0);
                }
                else
                {
                    frmHelp.SendCmd(4);
                }
            }
            txttip.Text += "命令已下发...\r\n";
            txttip.Select(txttip.Text.Length, 0);
            txttip.ScrollToCaret();
        }
    }
}


